简体   繁体   English

如何使用 curl --ftp-create-dirs?

[英]how to use curl --ftp-create-dirs?

Background背景

I have been searching the Internet trying to find an example of --ftp-create-dirs .我一直在网上搜索,试图找到--ftp-create-dirs的例子。

Overall my goal is to use "--ftp-create-dirs" to automatically create the necessary folders if they are not present when I upload my file.总的来说,我的目标是使用“--ftp-create-dirs”自动创建必要的文件夹,如果它们在我上传文件时不存在。

Problem问题

The problem is I don't know the exact syntax for properly using --ftp-create-dirs , can someone help me with this?问题是我不知道正确使用--ftp-create-dirs的确切语法,有人可以帮助我吗?

My current curl:我目前的卷曲:

curl -k -T 000-0000-0000-000.png -u [username]:[pass] --ftp-create-dirs /test --ftp-ssl  ftp:[ftp server]

In the example above, I am trying to upload the .png image and create /test on the ftp server if it does not exist.在上面的示例中,我尝试上传 .png 图像并在 ftp 服务器上创建/test (如果它不存在)。

通过 FTP 添加新目录:

curl ftp://username:password@10.10.10.10/homes/back/newdir/ --ftp-create-dirs

Just putting this in here for future reference (and because I keep making the same mistake that I just saw in your code): it is important to end your folder name with a / (slash).只是把它放在这里以供将来参考(因为我一直在犯我刚刚在你的代码中看到的同样错误):用/ (斜杠)结束你的文件夹名称很重要。 Otherwise, curl will create a file, not a folder.否则,curl 将创建一个文件,而不是一个文件夹。 Here is the command I used:这是我使用的命令:

curl -T path/to/local_file.txt ftp://1.2.3.4/my_new_folder/ --ftp-create-dirs -u username:password

This will move local_file.txt to my_new_folder on the FTP server.这会将local_file.txt移动到 FTP 服务器上的my_new_folder The folder will be created if it doesn't exist, otherwise, the command will simply be ignored.如果该文件夹不存在,则将创建该文件夹,否则,该命令将被忽略。

If there are any issues with creating the folder, curl will return error number 9 (see https://curl.haxx.se/libcurl/c/libcurl-errors.html ).如果创建文件夹有任何问题,curl 将返回错误号 9(参见https://curl.haxx.se/libcurl/c/libcurl-errors.html )。 This can happen if a file with the same name as the new folder already exists in the given directory:如果给定目录中已存在与新文件夹同名的文件,则会发生这种情况:

curl: (9) Failed to MKD dir: 451

You don't need to use the /test after the --ftp-create-dirs .您不需要在--ftp-create-dirs之后使用/test Its just a parameter similar to your -k (doesn't take any value) at the command.它只是一个类似于命令中的-k (不带任何值)的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM