Search code examples
.netftpwebrequestftpwebrequest

How to change directory permissions/chmod on FTP server using FtpWebRequest/WebRequest (C#)?


How to change directory permissions on FTP server using FtpWebRequest/WebRequest (C#)?

I've tried this, but without success (ftp unsupported method exception):

ftpPath = ftpPath.Replace(dirname, "");
var request = (FtpWebRequest)WebRequest.Create(ftpPath);
request.Credentials = new NetworkCredential(config.FtpUser, config.FtpPassword);
request.UsePassive = true;
request.UseBinary = true;

request.Method = "CHMOD 777 " + dirname;

using (var resp = (FtpWebResponse)request.GetResponse())

Any other suggestions?


Solution

  • The simplest way I found to do this was to use psftp.exe and batch the command. Reference: http://en.wikipedia.org/wiki/PuTTY

    I spawned psftp from System.Diagnostics.Process.Start() feeding it process start info. ...and wrote the commands into a text file that was referenced inside the process arguments It wasn't as smooth as I wanted it to be, but it did the trick.

    I have also seen (but not used) the chmod command embedded in the examples from the SSH library from: http://www.tamirgal.com/blog/page/SharpSSH.aspx

    -TH