日期:2014-05-20  浏览次数:20938 次

FtpWebRequest怎么移动文件
如题,FtpWebRequest怎么把一个ftp目录下的文件,移动到另外一个目录下?求指点!

------解决方案--------------------
把新路径+文件名赋值到RenameTo即可。
public bool Rename(string olName, string newName)
{
Uri serverUri = combineFileName(olName);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return false;
}
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(serverUri);
request.RenameTo = newName;
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.Rename;
request.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine("Status: {0}", response.StatusDescription);
response.Close();
}
return true;
}