Zumarta Zumarta - 3 months ago 40
C# Question

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.

Answer

You can change

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

to

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

:)

Comments