'SCP doesn't transfer files when using multifile bracket expansion
I'm attempting to use the scp command:
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. This was after trying to use the interactive shell test
[[ $- == *i* ]] || return
that seem to cause some problems.
I'm running the scp command from my OpenSuse 42.1 workstation. But I've also tried from a Redhat 6.3 system. 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 ---
Using the -vvv option against the problematic system shows the following version info:
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:
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?
--- edit 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. I'm just not sure what doc to look for or keyword to use (glob?):
https://unix.stackexchange.com/questions/123091/understand-debug-messages-from-sshd
http://www.openssh.com/specs.html
Ideas?
Solution 1:[1]
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.
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
.
But you might use sftp
, such as:
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.
Solution 2:[2]
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.
If that doesn't work, try rsync (tm)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |