将文件从一个文件夹移动到FTP中的其他文件夹

时间:2016-12-05 14:23:07

标签: c# asp.net asp.net-mvc-3 ftp-client ftpwebrequest

我要求在ftp中将文件从一个文件夹移动到另一个文件夹 我使用下面的代码块,但得到以下错误

远程服务器返回错误:(501)参数或参数中的语法错误。

 public void MoveFile(string source,string destination, string UserName, string Password)
    {
        FtpWebRequest ftpRequest = null;
        FtpWebResponse ftpResponse = null;
        try
        {
            ftpRequest = (FtpWebRequest)WebRequest.Create(source);
            ftpRequest.Credentials = new NetworkCredential(UserName, Password);
            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;
            ftpRequest.Method = WebRequestMethods.Ftp.Rename;
            ftpRequest.RenameTo = destination;
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            ftpResponse.Close();
            ftpRequest = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
你能帮我解决一下这个问题。

0 个答案:

没有答案