how to use curl --ftp-create-dirs?
Asked Answered
C

3

7

Background

I have been searching the Internet trying to find an example of --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.

Problem

The problem is I don't know the exact syntax for properly using --ftp-create-dirs, can someone help me with this?

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.

Clorindaclorinde answered 24/2, 2014 at 22:6 Comment(0)
F
5

To add a new directory via FTP:

curl ftp://username:[email protected]/homes/back/newdir/ --ftp-create-dirs
Ferruginous answered 21/1, 2016 at 16:5 Comment(0)
I
3

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 -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.

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) Failed to MKD dir: 451
Intervocalic answered 6/11, 2019 at 10:22 Comment(0)
Q
0

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.

Quintet answered 25/2, 2014 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.