Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

curl --ftp how to manage directories

Mon Mar 03, 2014 3:57 pm

Hi to all the community,
im using this code to upload all file from folder /data/386/file.log

Code: Select all

find /data/386 -type f -exec curl -u user:pass --ftp-create-dirs -T {} ftp://myftp.com/data/Post1/{} \;
the final result is: ftp://myftp.com/data/Post1/data/386/file.log
how can i change the code to obtain this result? ftp://myftp.com/data/Post1/file.log

thanks :oops:

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: curl --ftp how to manage directories

Mon Mar 03, 2014 5:36 pm

Do not specify {} in the FTP URL. Just the directory with a trailing slash.

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: curl --ftp how to manage directories

Mon Mar 03, 2014 8:03 pm

Sorry con you edit/correct my code? :oops:

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: curl --ftp how to manage directories

Mon Mar 03, 2014 11:08 pm

i made some test, thats the correct code:
must delete only the last {}

Code: Select all

find /data/386 -type f -exec curl -u user:pass --ftp-create-dirs -T {} ftp://myftp.com/data/Post1/ \;
thank you very much!!!

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: curl --ftp how to manage directories

Tue Mar 04, 2014 11:17 pm

there is a problem with the code, now it upload only the file, without any sub folders!

Code: Select all

find /data -type f -exec curl -u user:pass --ftp-create-dirs -T {} ftp://myftp.com/data/Post1/ \;
i need to upload this part: /data/386/file.log

with the code at the beginning of this post i optain this: ftp://myftp.com/data/Post1/file.log
how can i change the code to obtain this result? ftp://myftp.com/data/Post1/386/file.log

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: curl --ftp how to manage directories

Wed Mar 05, 2014 12:01 am

Raspimina wrote:i need to upload this part: /data/386/file.log
The easiest way is to be in the directory /data locally, so that the local name {} includes 386/file.log but not /data/. Then, put the {} back onto the destination:

Code: Select all

cd /data && find * -type f -exec curl -u user:pass --ftp-create-dirs -T {} ftp://myftp.com/data/Post1/{} \;

Raspimina
Posts: 58
Joined: Thu Feb 27, 2014 4:51 pm

Re: curl --ftp how to manage directories

Wed Mar 05, 2014 7:03 am

Great! Thanks very much!
It's a very easy solution :)

Return to “General discussion”