net-ssh / net-scp

Pure Ruby implementation of the SCP protocol
http://github.com/delano/net-scp
MIT License
152 stars 62 forks source link

I can't transfer multiple files at the same time #25

Open tomassliz opened 8 years ago

tomassliz commented 8 years ago

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" })
sonic0002 commented 7 years ago

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 *.

arsoedjono commented 7 years ago

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.