net-ssh/net-scp

I can't transfer multiple files at the same time

tomassliz opened this issue · 2 comments

I would like to copy multiple files with scp. With current implementation I have to call scp for each file. I can copy whole directory but I wish to copy only some files.

So instead of this:

Net::SCP.upload!("remote.host.com", "username",
  "/local/path/file1.rb", "/remote/path/",
  :ssh => { :password => "password" })

Net::SCP.upload!("remote.host.com", "username",
  "/local/path/file2.rb", "/remote/path/",
  :ssh => { :password => "password" })

I would like to use this:

Net::SCP.upload!("remote.host.com", "username",
  "/local/path/file*.rb", "/remote/path/",
  :ssh => { :password => "password" })

The issue actually being that * is escaped when the command is being built. Basically it's in the start_command method. When shellescape method is being called, * will be escaped. See below code in scp.rb.

str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")

Since * is escaped, the actual command being executed would look like

scp -f /remote_dir/\\*

This command will fail. Actually the issue should be resolved by updating the shellescape method to not escape *.

Hello, I want to ask about the same topic. How if I want to upload multiple files by separating file names by space? For example:

Net::SCP.upload!("remote.host.com", "username",
  "/local/path/file1.rb /local/path/file2.rb", "/remote/path/",
  :ssh => { :password => "password" })

I have tried the above example and got No such file or directory @ rb_file_s_stat - <file_names> (Errno::ENOENT) error.

Thanks.