How can I use FTP to move files between directories?

后端 未结 9 1895
日久生厌
日久生厌 2020-12-05 02:47

I have a program that needs to move a file from one directory to another on an FTP server. For example, the file is in:

ftp://1.1.1.1/MAIN/Dir1
9条回答
  •  生来不讨喜
    2020-12-05 03:32

    In following code example I tried with following data and it works.

    FTP Login location is "C:\FTP".

    File original location "C:\FTP\Data\FTP.txt".

    File to be moved, "C:\FTP\Move\FTP.txt".

    Uri serverFile = new Uri(“ftp://localhost/Data/FTP.txt");
    FtpWebRequest reqFTP= (FtpWebRequest)FtpWebRequest.Create(serverFile);
    reqFTP.Method = WebRequestMethods.Ftp.Rename;
    reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPass);
    reqFTP.RenameTo = “../Move/FTP.txt";
    
    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
    

提交回复
热议问题