简体   繁体   English

如何将文件从一个 FTP 移动到另一个 FTP?

[英]How to Move File From one FTP to another FTP?

i need to move file from one ftp to another ftp and change the name as well while moving the file.我需要将文件从一个 ftp 移动到另一个 ftp 并在移动文件时更改名称。 How to do it.怎么做。 can any one try to help me.任何人都可以尝试帮助我。

Try this:尝试这个:

        //FTP server 1 (Download)
        WebClient client = new WebClient();
        client.Credentials = new NetworkCredential("username", "password");
        client.DownloadFile(
        "ftp://ftp.example.com/remote/path/file.zip", @"C:\local\path\file.zip");

        //FTP server 2 (Upload)
        client.Credentials = new NetworkCredential("username", "password");
        client.UploadFile(
        "ftp://host/renamedFile.zip", WebRequestMethods.Ftp.UploadFile, localFile);

This downloads the file: "file.zip" from the first FTP server.这将从第一个 FTP 服务器下载文件:“file.zip”。 it saves it as file.zip, you can put any name you want there, then the second part uploads the renamedfile.zip, just change the name and path and it should work.它将它保存为file.zip,您可以在那里输入任何您想要的名称,然后第二部分上传重命名的file.zip,只需更改名称和路径,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM