本文介绍了用FtpWebRequest重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当将文件移动到另一个FTP位置时,您必须在新的FTP位置使用 RenameTo
。
When moving a file to another FTP location you must use RenameTo
with the new FTP location.
这个例子你如何使用 RenameTo
移动到新的FTP位置?
In this example how do you use RenameTo
to move to the new FTP location?
FtpWebRequest ftpRequest = null;
FtpWebResponse ftpResponse = null;
try
{
ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://mysite.com/folder1/fileName.ext");
ftpRequest.Credentials = new NetworkCredential("user", "pass");
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.Method = WebRequestMethods.Ftp.Rename;
ftpRequest.RenameTo = "ftp://mysite.com/folder2/fileName.ext";
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
ftpResponse.Close();
ftpRequest = null;
}
catch (Exception ex) { Label1.Text = (ex.ToString()); }
推荐答案
将目标路径设置为 .RenameTo
属性,而不是URL:
Set a target path to .RenameTo
property, not URL:
ftpRequest.RenameTo = "/folder2/fileName.ext";
根据MSDN文档:
As per MSDN documentation for FtpWebRequest.RenameTo
property:
与:
$ b
Compare to WebRequest.Create
method:
这篇关于用FtpWebRequest重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!