15

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.

4
  • Let me just note that some obvious "solution" is to rename the file, copy it, and rename it back on the remote server. Commented Aug 7, 2014 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.) Commented Aug 7, 2014 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. Commented Aug 7, 2014 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 [email protected]:/tmp Commented Mar 4, 2018 at 5:05

3 Answers 3

28

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.

6

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

scp ./file\:with\:colons.txt remoteserver:
8
  • 2
    You don't need to escape colon. Commented Aug 7, 2014 at 9:58
  • Your escaping of : is at shell level, not at scp level. Commented Aug 7, 2014 at 10:00
  • Yes, you need to escape. At least in my shell I need the escape. Commented Aug 7, 2014 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. Commented Aug 7, 2014 at 10:03
  • I was wrong. scp ./test.json-2014-08-07T11:17:58.662378 remote:tmp/ does actually work! Sorry. Commented Aug 7, 2014 at 10:06
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)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.