我尝试使用以下代码将 FTP 文件从一个位置移动到另一个位置,但我遇到了问题。
代码:
Uri serverFile = new Uri("ftp://3.222.001.114/ftproot/Incomming/ProcessedFiles/Test.xml");
FtpWebRequest reqFTP= (FtpWebRequest)FtpWebRequest.Create(serverFile);
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
reqFTP.Credentials = new NetworkCredential("ftpuser", "test123");
reqFTP.RenameTo = "ftp://3.222.001.114/ftproot/Incomming/ProcessedFiles/Test/Test.xml";
reqFTP.GetResponse().Close();
但我遇到以下错误:
Additional information: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
如果以任何其他方式移动 FTP 文件。
请帮我解决
最佳答案
试试这个:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://3.222.001.114/ftproot/Incomming/ProcessedFiles/Test.xml");
request.Method = WebRequestMethods.Ftp.Rename;
request.Credentials = new NetworkCredential("ftpuser", "test123");
request.RenameTo = "../Test/Test.xml"; //Relative path
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
关于c# - 如何将FTP文件移动到C#中的另一个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37803202/