FTP:自动创建嵌套目录
我们正在尝试将文件移动到 FTP 站点。我们需要创建一个像这样的文件夹结构:
/deeply/nested/folder/struct/index.html
昨天,我们意识到我们无法一次创建多个文件夹,所以这是行不通的:
MKD /深层/嵌套/文件夹/结构
因此,在代码中,我们编写了一个循环来创建每个文件夹,一次一个,忽略由已存在的文件夹引起的错误。忽视错误是很恶心的。
是否有一种方法可以通过一个操作而不是多个操作来创建这些嵌套文件夹?有没有命令可以查看文件夹是否已存在?如果我们只是推送包含完整路径的文件,FTP 是否足够智能来为我创建目录?
We are trying to move a file to an FTP site. We need to create a folder structure like this:
/deeply/nested/folder/structure/index.html
Yesterday, we realized we can't create more than one folder at a time, so this doesn't work:
MKD /deeply/nested/folder/structure
So, in code, we wrote a loop that created each folder, one at a time, ignoring errors caused by the folder already existing. Ignoring errors is gross.
Is a way to create these nested folders in one action, rather than multiple? Is there a command to see if a folder already exists? If we just push the file out including the full path, will FTP be smart enough to create the directories for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有创建包含子文件夹的文件夹的标准方法。也没有标准方法来检查目录是否存在。您需要使用 LIST 或 MLSD(如果支持)并解析结果。您不能只使用一些支持所需功能的第三方组件吗?
No, there's no standard way to create a folder with subfolders. There's also no standard way to check if directory exists. You would need to use LIST or MLSD (where supported) and parse the result for this. Can't you just use some third-party component that supports the needed functionality?
我在这里写了一个简单的 C# 示例,也许有人会需要这段代码。
I wrote a simple C# example here, maybe someone will need this code.