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

て烟熏妆下的殇ゞ 提交于 2019-12-13 16:32:37

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/6660121/how-to-change-directory-permissions-chmod-on-ftp-server-using-ftpwebrequest-webr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!