使用多文件括号扩展时,SCP无法传输文件

时间:2016-03-25 03:31:36

标签: linux scp

我试图使用scp命令:

scp user@remotehost:/dir/to/\{file1,file2\} . 

但是当我运行它时,它会提示输入密码,然后在不传输文件的情况下结束。如果我运行以下命令:(删除反斜杠 - 保持相同的用户,主机和文件名):

scp user@remotehost:/dir/to/{file1,file2} .

然后运行正常。好的,我的意思是它会为每个文件提示一次,但它会传输文件。

我还尝试重命名我的.bashrc.bash_profile,以防这些配置文件中的某些内容导致问题。这是在尝试使用交互式shell测试

之后
[[ $- == *i* ]] || return

这似乎会导致一些问题。

我从 OpenSuse 42.1 工作站运行 scp 命令。但我也尝试过 Redhat 6.3 系统。我没有终端访问系统我试图从中获取文件。

如果我对同一工作站上的另一台机器运行命令(带斜线 - 以便它只提示一次),那么它会按预期运行。

---编辑1 ---
对有问题的系统使用-vvv选项会显示以下版本信息:

debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version SSHD
debug1: no match: SSHD

对可行的系统使用-vvv选项显示以下内容:

debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000

我发现远程软件版本存在明显差异。但是,SSHD是真正的版本还是可能被掩盖/隐藏的版本?

---编辑2 ---
我发现这两个链接描述了不匹配的结果,它以与SSH协议版本2规范兼容的模式运行。我只是不确定要查找的文档或要使用的关键字(glob?):
https://unix.stackexchange.com/questions/123091/understand-debug-messages-from-sshd

http://www.openssh.com/specs.html

想法?

1 个答案:

答案 0 :(得分:2)

scp user@remotehost:/dir/to/\{file1,file2\} . 

仅当远程端评估能够进行大括号扩展的shell中的远程命令时才有效。客户发送:

debug1: Sending command: scp -v -f /dir/to/\{file1,file2\}

位于openssh passed as an argument用户的默认shell中,即使没有scp代码中的glob也可以使用。

在某些系统上无效的原因可能是shell或不同的ssh实施,可能无法通过用户shell传递参数。

但您可以使用sftp,例如:

sftp -b <(echo get /dir/to/{file1,file2} ) user@remotehost

这将以批处理模式运行sftp,在您的客户端上执行大括号扩展并获取您感兴趣的所有文件。

相关问题