14

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 07 '14 at 09: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 07 '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 07 '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 04 '18 at 05:05

3 Answers3

27

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.

cuonglm
  • 153,898
6

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

scp ./file\:with\:colons.txt remoteserver:
Karel
  • 1,468
  • 2
    You don't need to escape colon. – cuonglm Aug 07 '14 at 09:58
  • Your escaping of : is at shell level, not at scp level. – ctrl-alt-delor Aug 07 '14 at 10:00
  • Yes, you need to escape. At least in my shell I need the escape. – Finn Årup Nielsen Aug 07 '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 07 '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 07 '14 at 10:06
  • @Gnouc @FinnÅrupNielsen In bash some characters including : and @ require escaping when tab completion is used, but if you type the entire command without using tab completion it will work with or without escaping. – kasperd Aug 07 '14 at 11:28
  • @kasperd: I think it's not required. It's a feature of bash completion. : and @ in string don't have special meaning to shell. – cuonglm Aug 07 '14 at 11:33
  • @Gnouc It is required if you want tab completion to work. If you type the : or @ in a name without escaping and try to complete the rest of the name by pressing tab, it won't work. – kasperd Aug 07 '14 at 11:36
0

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)