Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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 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.) –  richard Aug 7 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 at 16:32

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer

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

scp ./file\:with\:colons.txt remoteserver:
share|improve this answer
2  
You don't need to escape colon. –  cuonglm Aug 7 at 9:58
    
Your escaping of : is at shell level, not at scp level. –  richard Aug 7 at 10:00
    
Yes, you need to escape. At least in my shell I need the escape. –  Finn Årup Nielsen Aug 7 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 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 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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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