Ftp.MakeDirectory 嵌套结构
如果你们没有在 ftp 上创建子目录的权限,你们会怎么做? 显然,您无法在一个命令中创建目录
,因此:
path = "ftp://someftp.com/files/newFolder/innerFolder";
var request = (FtpWebRequest)WebRequest.Create(path);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
var response = (FtpWebResponse)request.GetResponse());
如果“files”或“newFolder”已存在,则会抛出错误代码为 550 的异常
如何检查我是否有权创建子目录?< /p>
如果我没有这些权利我该怎么办?请向我展示可让您在多个命令中创建文件夹结构的代码。
What do you guys do if you lack of permissions to create subdirs on a ftp?
Apparently you can't create a directory in one command
So this:
path = "ftp://someftp.com/files/newFolder/innerFolder";
var request = (FtpWebRequest)WebRequest.Create(path);
request.Method = WebRequestMethods.Ftp.MakeDirectory;
var response = (FtpWebResponse)request.GetResponse());
will throw an exception with error code 550 if 'files' or 'newFolder' is already exists
How can I check if I have the rights to create subdirs?
What can I do if I don't have those rights? Show me please code that lets you create a folder structure in more than one command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧:因为
FtpWebRequest
是无状态的 - 无法更改 FTP 上的当前目录。幸运的是,我们可以使用开源 FTP 库之一。以下是 AlexPilotti 的 FTPS 库的示例,可通过 NuGet 获取Alright: because
FtpWebRequest
is stateless - there is no way to change current directory on FTP. Fortunately we can use one of the open-source FTP libraries. Here's an example with AlexPilotti's FTPS library, which is availible through NuGet你是对的。您无法使用一条命令创建 FTP 的完整路径。最简单的方法可能如下:
因此本质上,它在两个限制条件下变得递归,发生非路径异常并且没有任何东西可以修剪。
You are correct. You cannot create an entire path in one command to FTP. The simplest way to do is probably as follows:
So essentially, it becomes recursive with two limit conditions, non-path exceptions occurring and nothing left to trim.