I am trying to copy a file that has colons and periods, e.g., with:

scp "test.json-2014-08-07T11:17:58.662378" remote:tmp/

scp test.json-2014-08-07T11\:17\:58.662378 remote:tmp/

and combinations with file:

scp "file:///home/.../test.json-2014-08-07T11:17:58.662378" remote:tmp/

My guess is that scp tries to interprete parts of the file as a server and/or port number. How do I avoid that?

If I rename the file to test.json then scp test.json remote:tmp/ works ok, but not even scp test*62378 remote:tmp/works.

  • Let me just note that some obvious "solution" is to rename the file, copy it, and rename it back on the remote server. – Finn Årup Nielsen Aug 7 '14 at 9:52
  • An explanation of why globs (*), don't work. It is done in shell, so exactly the same text (argument) will be passed to scp. You need to change the text (argument) that is passed to scp. (see answer below, for what to change text argument to.) – ctrl-alt-delor Aug 7 '14 at 10:05
  • It should be noted that : is an illegal filename character on OSX, so if you ever need to transfer these files there it's something to keep in mind. – Daenyth Aug 7 '14 at 16:32
  • In cygwin, if the filename starts with a hyphen you can prefix the file with a double hyphen e.g. scp -- -1.JvSbrpchxuk.png user@example.com:/tmp – Shane Rowatt Mar 4 '18 at 5:05

Use ./ before your filename:

scp ./test.json-2014-08-07T11:17:58.662378 remote:tmp/

That make scp know it's a file. Without it, scp thinks it's a hostname because of the colon.


Use the path by prepending ./ and escape your :'s. Cyberiti has more info. Example:

scp ./file\:with\:colons.txt remoteserver:
  • 2
    You don't need to escape colon. – cuonglm Aug 7 '14 at 9:58
  • Your escaping of : is at shell level, not at scp level. – ctrl-alt-delor Aug 7 '14 at 10:00
  • Yes, you need to escape. At least in my shell I need the escape. – Finn Årup Nielsen Aug 7 '14 at 10:01
  • @FinnÅrupNielsen: What is your shell? You don't need to escape colon, the shell add backslash for you. You can remove them and see it still works. – cuonglm Aug 7 '14 at 10:03
  • I was wrong. scp ./test.json-2014-08-07T11:17:58.662378 remote:tmp/ does actually work! Sorry. – Finn Årup Nielsen Aug 7 '14 at 10:06

Apparently, I did not try this version with path prefix:

scp /home/.../test.json-2014-08-07T11\:17\:58.662378 remote:tmp/

this also works:

scp ./test.json-2014-08-07T11\:17\:58.662378 remote:tmp/

From https://twitter.com/h0pbeat/status/497319751031353344 and http://www.cyberciti.biz/faq/rsync-scp-file-name-with-colon-punctuation-in-it/ Thanks.

(as the above users managed to answer before me)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.