scp command line copy file to destination path with space.
今天准备用把一个文件拷贝到远程电脑的移动硬盘上
远程路径是 /media/username/My Passport
注意“My Passport”带了空格符,对于路径来讲属于特殊符号。
尝试一: 单引号
一开始拷贝的时候我用了如下命令
scp -r source_dir 'username@192.168.1.103:/media/username/My Passport'
用了单引号,结果就出现错误
scp: ambiguous target
尝试二:转移符“\”
然后以为单引号可能识别不了,就用转移符“\”
scp -r source_dir username@192.168.1.103:/media/username/My\ Passport
结果还是出现错误
scp: ambiguous target
解决方案
后来通过linux论坛查找,终于找到方法,需要再路径那里加转移符
scp -r source_dir username@192.168.1.103:"/media/username/My\\ Passport"
然后等待输入密码就可以了
大功告成
论坛地址:https://superuser.com/questions/1022976/scp-copy-has-error-ambiguous-target
scp myfile.txt user@192.168.1.100:"/file\\ path\\ with\\ spaces/myfile.txt"