How do you copy a file on an FTP server? My goal is to copy ftp://www.mysite.com/test.jpg
to ftp://www.mysite.com/testcopy.jpg
. To rename a file, I would use:
var request = (FtpWebRequest)WebRequest.Create("ftp://www.mysite.com/test.jpg");
request.Credentials = new NetworkCredential(user, pass);
request.Method = WebRequestMethods.Ftp.Rename;
request.RenameTo = "testrename.jpg"
request.GetResponse().Close();
FtpWebResponse resp = (FtpWebResponse)request.GetResponse();
However, there is no Method for copying files. How would you do copy a file?
Try this:
This downloads the file to a stream, and then uploads it.
I guess you can't really do this with FTP. What you can do is download the file you want to copy and then upload it with a new name. For example:
FtpWebRequest is a lightweight class. Microsoft felt it should be used by simple client to download and delete the files once the client is finish.
In our project we did someting like this