Zumarta Zumarta - 2 months ago 22x
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
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.


You can change

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


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