bash 如何使用 curl --ftp-create-dirs?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22000102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use curl --ftp-create-dirs?
提问by WorkerBee
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 图像并/test
在 ftp 服务器上创建(如果它不存在)。
回答by Arthur Savage
To add a new directory via FTP:
通过 FTP 添加新目录:
curl ftp://username:[email protected]/homes/back/newdir/ --ftp-create-dirs
回答by monsterbacke
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. Here is the command I used:
只是把它放在这里以供将来参考(因为我一直在犯我刚刚在你的代码中看到的同样错误):用/
(斜杠)结束你的文件夹名称很重要。否则,curl 将创建一个文件,而不是一个文件夹。这是我使用的命令:
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. The folder will be created if it doesn't exist, otherwise, the command will simply be ignored.
这将移动local_file.txt
到my_new_folder
FTP 服务器上。如果文件夹不存在,则将创建该文件夹,否则,该命令将被忽略。
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). This can happen if a file with the same name as the new folder already exists in the given directory:
如果创建文件夹有任何问题,curl 将返回错误号 9(参见https://curl.haxx.se/libcurl/c/libcurl-errors.html)。如果给定目录中已存在与新文件夹同名的文件,则会发生这种情况:
curl: (9) Failed to MKD dir: 451
回答by Sabuj Hassan
You don't need to use the /test
after the --ftp-create-dirs
. Its just a parameter similar to your -k
(doesn't take any value) at the command.
您不需要/test
在--ftp-create-dirs
. 它只是一个类似于您-k
在命令中的参数(不带任何值)。