Zumarta
Zumarta

Reputation: 145

Rename directory on FTP server using FtpWebRequest

I want to rename a folder on my FTP server that contains n files.

My approach, after checking if the directory is existing, was:

FtpWebRequest request = (FtpWebRequest) WebRequest.Create(ftpDirectory);
request.Method = WebRequestMethods.Ftp.Rename;
request.Credentials = credentials;
request.RenameTo = folderNameThen;

The variable ftpDirectory contains the whole address to the directory:

string ftpDirectory = "ftp://" + ftpServer + "/" + folderToRename + "/";

But I got an exception:

The requested URI is invalid for this FTP command.

But I couldn't image how the path should look like to rename the folder if mine isn't correct.

Upvotes: 0

Views: 2100

Answers (1)

uTeisT
uTeisT

Reputation: 2266

You can change

string ftpDirectory = "ftp://" + ftpServer + "/" + folderToRename + "/";

to

string ftpDirectory = "ftp://" + ftpServer + "/" + folderToRename; 

:)

Upvotes: 2

Related Questions