Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I upload a file named yes, this filename has a comma.txt with the cli curl?

You would normally do this to upload a file with curl:

curl --progress-bar -F "fileUpload=@filename.txt"

However curl interprets commas as multiple files to upload, so this will not work:

curl --progress-bar -F "fileUpload=@yes, this filename has a comma.txt"

How can I escape the filename?

I already found a workaround by creating a temporary symlink to the original file and pass that to curl. However the problem is that the filename that curl sends to the server is the filename of the symlink, not the original file.

share|improve this question
up vote 3 down vote accepted

You have not said what OS you are using. The following solutions work for Linux (not only for curl but most kinds of escaping:

  • Put the file name in quotes (you need to escape them as well):

    curl --progress-bar -F "fileUpload=@\"yes, this filename has a comma.txt\"" 
  • Escape the comma

    curl --progress-bar -F "fileUpload=@yes\, this filename has a comma.txt" 
share|improve this answer
I'm using Mac OS X 10.8.2, only the quoting worked. The one where the comma is escaped, tries to upload a file called "yes" (curl: (26) couldn't open file "yes\"). – Tyilo May 1 '13 at 16:56
On Mac OSX 10.9.4, I had to put the quotes after the @ like so: curl --progress-bar -F "fileUpload=@\"yes, this filename has a comma.txt\"" – spyle Sep 23 '14 at 17:00
Had same problem as spyle on Ubuntu 14.04. Terdon's answer actually sends the literal filename instead of the contents of the file. – Cory R. King Feb 5 '15 at 0:49
@CoryR.King yes, of course, that's intentional. How else would it work? To send the file's contents, you would need to specify a remote file name to write to. – terdon Feb 5 '15 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .