I'm trying to upload all the text files within the current folder via FTP to a server location using curl. I tried the following line:
curl -T "{file1.txt, file2.txt}" ftp://XXX --user YYY
where XXX is the server's IP address and YYY is the username and password.
I'm able to transfer file1.txt to the server successfully, but it complains about the second file saying 'Can't open 'file_name'!'
I swapped the file names and it worked for file2.txt and not file1.txt. Seems like I've got the syntax wrong, but this is what the manual says?
Also, ideally I would be able to do something like this:
curl -T *.txt ftp://XXX --user YYY
because I won't always know the names of the txt files in the current folder or the number of files to be transferred.
I'm of the opinion I may have to write a bash script that collects the output of ls *.txt
into an array and put it into the multiple-files-format required by curl.
I've not done bash scripting before – is this the simplest way to achieve this?
Best Answer
Your first command should work without whitespaces:
Also note the trailing "/" in the URLs above.
This is curl's manual entry about option "-T":
"*.txt" expansion does not work because curl supports only the same syntax as for URLs:
But you could use the "normal" shell globbing like this:
(The last example may not work in all shells or with any kind of exotic file names.)