简体   繁体   English

使用多文件括号扩展时 SCP 不传输文件

[英]SCP doesn't transfer files when using multifile bracket expansion

I'm attempting to use the scp command:我正在尝试使用 scp 命令:

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

But when I run this, it prompts for password and then ends without transferring the files.但是当我运行它时,它会提示输入密码,然后在不传输文件的情况下结束。 If I run following command: (removing the backslashes - keeping same user, host and file names):如果我运行以下命令:(删除反斜杠 - 保留相同的用户、主机和文件名):

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

then it runs okay.然后它运行正常。 By okay, I mean that it prompts once for each file but it does transfer the files.好的,我的意思是它会为每个文件提示一次,但它确实会传输文件。

I have also tried to rename my .bashrc and .bash_profile just in case it was something in these profiles that were causing problems.我还尝试重命名我的.bashrc.bash_profile以防这些配置文件中的某些内容导致问题。 This was after trying to use the interactive shell test这是在尝试使用交互式 shell 测试之后

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

that seem to cause some problems.这似乎会引起一些问题。

I'm running the scp command from my OpenSuse 42.1 workstation.我正在从我的OpenSuse 42.1工作站运行scp命令。 But I've also tried from a Redhat 6.3 system.但我也试过从Redhat 6.3系统。 I do not have terminal access to the system I'm trying to get files from.我没有终端访问我试图从中获取文件的系统。

If I run the command (with slashes - so that it only prompts once) against a different machine from my same workstation then it works as expected.如果我在同一工作站的另一台机器上运行命令(带斜杠 - 这样它只提示一次),那么它会按预期工作。

--- edit 1 --- --- 编辑 1 ---
Using the -vvv option against the problematic system shows the following version info:针对有问题的系统使用 -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

Using the -vvv option against the system that works shows the following:对工作的系统使用-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

I see an obvious difference in remote software version.我发现远程软件版本存在明显差异。 But, is SSHD a real version or is the version possibly being masked/hidden?但是,SSHD 是真实版本还是可能被屏蔽/隐藏的版本?

--- edit 2 --- --- 编辑 2 ---
I found these two links that describe the result of no match and it operating in a mode compatible with SSH protocol version 2 specification.我发现这两个链接描述了不匹配的结果,它以与 SSH 协议版本 2 规范兼容的模式运行。 I'm just not sure what doc to look for or keyword to use (glob?):我只是不确定要查找什么文档或要使用的关键字(glob?):
https://unix.stackexchange.com/questions/123091/understand-debug-messages-from-sshd https://unix.stackexchange.com/questions/123091/understand-debug-messages-from-sshd

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

Ideas?想法?

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

Works only if the remote side evaluates the remote command in the shell capable of brace expansion. 仅当远程端在支持大括号扩展的外壳中评估远程命令时,该方法才有效。 The client sends: 客户端发送:

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

which is in openssh passed as an argument to user's default shell, which makes it working even without glob in scp code. 它在openssh 作为参数传递给用户的默认shell,这使其即使在scp代码中没有glob的情况下也可以正常工作。

The reason why to does not work on some systems might be different shell or different ssh implementation that might not pass the arguments over the users shell . to在某些系统上不起作用的原因可能是不同的shell或不同的ssh实现,它们可能无法通过用户shell传递参数。

But you might use sftp , such as: 但是您可以使用sftp ,例如:

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

This will run sftp in batch mode, do the brace expansion on your client and gets you all the files you are interested in. 这将以批处理模式运行sftp ,在客户端上进行括号扩展,并获取您感兴趣的所有文件。

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

The glob and bracket expression must be enclosed in single quotes to be interpreted by the remote server assuming your shell there is bash-like.假设您的 shell 是类似 bash 的,则 glob 和括号表达式必须用单引号引起来,以便远程服务器进行解释。

If that doesn't work, try rsync (tm)如果这不起作用,请尝试 rsync (tm)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM