Here is the code

FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://xxx.xxx.xx//Versions/" + (isStable ? "S1.noext" : "T1.noext")); ftp.Proxy = null; ftp.Credentials = new NetworkCredential("login", "password"); ftp.Method = WebRequestMethods.Ftp.Rename; ftp.RenameTo = "Test.noext"; WebResponse disp = ftp.GetResponse(); disp.Close(); 

If the first time it is run on one file, the file is successfully renamed, and if it is run a second time on another file in the same directory, an error will pop up in GetResponse:

The remote server returned an error: (550) The file is not available (for example, it was not found or it cannot be accessed)

I tried to set the URI ( ftp: //xxx.xxx.xx/asd/ and ftp: // xxx: xxx@xxx.xxx.xx/asd/ ) in different ways, nothing happened, the same thing. How to solve this problem?

    1 answer 1

    Are you sure that at the second iteration you do not execute the method with the same ftp.RenameTo = "Test.noext"; as for the first time?

    RenameTo cannot replace a file, i.e. if the server already has a file with the name specified in RenameTo , then there will be an error.

    To avoid this situation, first delete the existing file with a separate request ( ftp.Method = WebRequestMethods.Ftp.DeleteFile )