【发布时间】:2014-03-11 08:50:34
【问题描述】:
您好,当我尝试重命名 ftp 站点上的文件时,我的 C# 程序出现问题。它在执行重命名过程时返回错误。但它可以下载我尝试重命名的文件,也可以在 ftp 服务器上上传文件,所以我猜这与权限无关。
我还尝试使用我在程序中使用的相同登录名在命令提示符下执行此操作,但没有遇到任何错误。我成功地重命名了上面的任何文件。
错误信息是这样的:
远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。
这是我重命名文件的代码:
public void rename(string currentFileNameAndPath, string newFileName)
{
try
{
/* Create an FTP Request */
ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + currentFileNameAndPath);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(user, pass);
/* When in doubt, use these options */
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = false;
ftpRequest.KeepAlive = false;
ftpRequest.Proxy = null;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.Rename;
/* Rename the File */
ftpRequest.RenameTo = newFileName;
/* Establish Return Communication with the FTP Server */
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
/* Resource Cleanup */
ftpResponse.Close();
ftpRequest = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return;
}
【问题讨论】:
-
这可能是一些事情。很可能您没有重命名(修改)文件的权限,但有读取权限。您还检查过函数中调用的当前和新文件名的路径实际上构造正确且有效吗?