Search code examples
c#ftpftpwebrequestftpwebresponse

Check FTP delete permission without trying to delete a file


I have to check whether an FTP Server allows me to delete a file or not. Without deleting an existing file or sending a file and trying to delete that file. For now, I use the 'Send a file and try to Delete it' dummy solution, but sometimes I don't have write permission.

I tried the code below using Chilkat library, but as I know, there are only Read, Write and Execute attributes, and the Delete attribute doesn't exist.

var ftp = new Chilkat.Ftp2();

ftp.Hostname = "127.0.0.1";
ftp.Username = "test";
ftp.Password = "test";

ftp.AuthTls = false;
ftp.PassiveUseHostAddr = true;


ftp.Connect();

// To get file permissions in UNIX format, disallow MSLD:
ftp.AllowMlsd = false;

if (ftp.GetDirCount() > 0)
{
    textBox1.AppendText("The permissions format is: " + ftp.GetPermType(0));
    textBox1.AppendText("\r\n");
}

for(var i = 0; i < ftp.GetDirCount();++i)
{ 
    // Display the permissions and filename
    textBox1.AppendText(ftp.GetPermissions(i) + " " + ftp.GetFilename(i));
    textBox1.AppendText("\r\n");
}

ftp.Disconnect();

So, according to my explanation above, Is it possible to determine whether the FTP server has Delete File permission or not? If yes,


Solution

  • There's no API in FTP protocol to test for permissions.

    You can try to interpret the permissions you get from the FTP directory listing.

    But for example on *nix systems, the listing never gives you enough information for such decision.

    Btw, on *nix servers, you have permissions to delete a file, if you have write permissions to its parent directory. What is the same permissions for for creating a new file. So normally, if you can create a file, you can delete a file. But FTP servers commonly impose another permissions on top of the system permissions. And those usually include separate permissions for creating and deleting files.