简体   繁体   中英

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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