c# - 如何将FTP文件移动到C#中的另一个目录?

标签 c# ftp file-rename

我尝试使用以下代码将 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/

相关文章:

linux - 如何在浏览器中下载 FTP 服务器上的文件?

java - 如何从 LPRT ftp 命令获取 IPv6

java - 如何在流式传输时重命名放置在远程位置的文件

linux - 根据条件在 Linux 中重命名文件名

c# - ICloneable接口(interface)

c# - 无法解析 .Net Core 3.1 中的 System.Windows.Forms.dll

android - 使用 DownloadManager 下载 .apk

python - 根据文档文本字符串重命名多个文件

c# - 如何模拟从泛型参数继承?

c# - 网格和图像重叠边框?