vst*_*der 2 linux bash scp openssh
我正在编写一个 shell 脚本,用于使用scp
. 如果目标目录不存在,我会收到误导性错误消息。IE:
scp user@remote-host:/path/to/existing/file /local/non-existing/directory/
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
/local/non-existing/directory/: Is a directory
Run Code Online (Sandbox Code Playgroud)
这是令人费解的......我希望是这样的:
Directory /local/non-existing/directory/ does not exist
Run Code Online (Sandbox Code Playgroud)
找到了相关的bug。它似乎已在 Ubuntu 14.04.5 (openssh 1:6.6p1-2ubuntu2.8) 中修复
Redhat 错误报告中有一个解释:
这个问题也存在于原始的 openSSH 中,当您尝试将某些内容复制到具有现有父目录的不存在目录中时会出现此问题。缺少对该边界条件的检查。当 scp 进程尝试写入上述文件时会抛出错误消息,但该文件以斜杠结尾(这是对目录的解释),这就是当前错误消息的原因。
无法重现(在 Ubuntu 14.04.5 LTS 和 Linux Mint 17 上测试)
如果/local/non-existing/directory
不存在,则scp
失败:
/local/non-existing/directory: No such file or directory
Run Code Online (Sandbox Code Playgroud)如果/local/existing/directory
存在,scp
复制file
到/local/existing/directory/file
如果remote-host:/path/to/existing/file
是目录,则scp
失败:
scp: file: not a regular file
Run Code Online (Sandbox Code Playgroud)ssh user@remote-host "file /path/to/existing/file"
Run Code Online (Sandbox Code Playgroud)
应该为您提供有关远程文件(或可能的目录)的信息。
file /local/non-existing/directory/
Run Code Online (Sandbox Code Playgroud)
应该为您提供有关本地目录的信息
mkdir -p /local/non-existing/directory/
Run Code Online (Sandbox Code Playgroud)
将递归创建目录,并在必要时创建任何父目录。
之后mkdir -p
,如果file
真的是一个文件并且/local/non-existing/directory/
真的是一个目录,那么您的scp
命令应该可以工作。
归档时间: |
|
查看次数: |
5416 次 |
最近记录: |