28

I want to upload all the files in one directory, and I know how to upload one file using curl like this :

curl -T "local/xxx.suffix" -u xxx:psw "ftp://192.168.1.158/public/demon_test/xxx.suffix"

How can I upload all the files (subdirectory) in the current directory to an FTP server?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
demon
  • 833
  • 1
  • 10
  • 20

2 Answers2

78

Use curl with find to recursively upload all files from a specific directory:

find mydir -type f -exec curl -u xxx:psw --ftp-create-dirs -T {} ftp://192.168.1.158/public/demon_test/{} \;
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • 3
    How can i enhance this command line to get the filename of each uploaded file? – arbyter Nov 05 '14 at 09:27
  • 3
    how could I do this without uploading the original folder but just it's contents? – ProblemsOfSumit Aug 10 '16 at 20:03
  • 1
    @ProblemsOfSumit Then you just need to remove the last {} from the url – Chuan Jun 19 '19 at 13:50
  • 1
    I don't think this is an optimal solution for uploading several files, as `curl` will disconnect after every file upload and reconnect again for the next file, which will slow down the process terribly – ManSamVampire Aug 20 '21 at 11:11
7

instead of curl, use wput (not to be confused with wget).