当要复制的路径和/或文件名有空格时,如何 scp?

Ric*_*Bou 8 scp filenames

我在远程remote_host文件中有这样的文件:

\home\user\path with spaces\filename with spaces.ext

我想要scp它到当前 dir .。我怎样才能做到这一点?

谢谢!

Ric*_*Bou 14

经过一番调查,我找到了这两个选项:

scp 'user@remote_host:"/home/user/path with spaces/filename with spaces.ext"' .

scp 'user@remote_host:/home/user/path\ with\ spaces/filename\ with\ spaces.ext' .

我希望它也能帮助你!

玩得开心!

编辑 - openssh 更新了一项安全功能,该功能会导致路径名中的某些字符出现错误消息“协议错误:文件名与请求不匹配”。在这种情况下,使用 scp 的新-T选项将允许它工作。例如

scp -T 'user@remote_host:"/home/user/path with spaces/filename with spaces and (2018).ext"' .

这在/sf/answers/3821952851/ 中有解释