user160185
user160185

Reputation: 71

FtpWebRequest move file

I am putting together a simple app and I have it working for uploading, downloading, deleting files using FtpWebRequest. But I cannot find how to move a file using FtpWebRequest. What is the simplest way to move a file from one dir to another without using another external dependancy? Thanks in advance.

Upvotes: 7

Views: 6894

Answers (1)

PVitt
PVitt

Reputation: 11760

Create a FtpWebRequest with the source file name, set the Method-Property of the FtpWebRequest to Use System.Net.WebRequestMethods.Ftp.Rename and set the RenameTo-Property of the FtpWebRequest to the new file name.

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("oldName");
request.Method = System.Net.WebRequestMethods.Ftp.Rename;
request.RenameTo = "newName";

Upvotes: 12

Related Questions