Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In a nutshell:
Net::SCP.upload!("remote.host.com", "username",
"/local/path", "/remote/path",
:ssh => { :password => "password" })

# upload recursively
Net::SCP.upload!("remote.host", "username", "/path/to/local", "/path/to/remote",
:ssh => { :password => "foo" }, :recursive => true)
Expand All @@ -42,6 +42,11 @@ In a nutshell:
"/remote/path", "/local/path",
:ssh => { :password => "password" })

# download a file from a remote server with a speed limit (kbps)
Net::SCP.download!("remote.host.com", "username",
"/remote/path", "/local/path",
:limit => 400, :ssh => { :password => "password" })

# download a file to an in-memory buffer
data = Net::SCP::download!("remote.host.com", "username", "/remote/path")

Expand Down
7 changes: 6 additions & 1 deletion lib/net/scp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ module Net
# be sent to indicate the modification and access times of each file.
# * "-r" -- recursive transfers should be allowed. Without this, it is an
# error to upload or download a directory.
# * "-l" -- limit the speed of transfers. The value of :limit wil be use
# as the value in the -l command.
#
# After those flags, the name of the remote file/directory should be passed
# as the sole non-switch argument to scp.
Expand Down Expand Up @@ -265,6 +267,7 @@ def initialize(session)
# * :chunk_size - the size of each "chunk" that should be sent. Defaults
# to 2048. Changing this value may improve throughput at the expense
# of decreasing interactivity.
# * :limit - Limits the speed of the transfer. Defaults no limit is set.
#
# This method will return immediately, returning the Net::SSH::Connection::Channel
# object that will support the upload. To wait for the upload to finish,
Expand Down Expand Up @@ -293,6 +296,7 @@ def upload!(local, remote, options={}, &progress)
# * :preserve - the atime and mtime of the file should be preserved.
# * :verbose - the process should result in verbose output on the server
# end (useful for debugging).
# * :limit - limit the speed of the transfer.
#
# This method will return immediately, returning the Net::SSH::Connection::Channel
# object that will support the download. To wait for the download to finish,
Expand Down Expand Up @@ -326,14 +330,15 @@ def download!(remote, local=nil, options={}, &progress)

# Constructs the scp command line needed to initiate and SCP session
# for the given +mode+ (:upload or :download) and with the given options
# (:verbose, :recursive, :preserve). Returns the command-line as a
# (:verbose, :recursive, :preserve, :limit). Returns the command-line as a
# string, ready to execute.
def scp_command(mode, options)
command = "scp "
command << (mode == :upload ? "-t" : "-f")
command << " -v" if options[:verbose]
command << " -r" if options[:recursive]
command << " -p" if options[:preserve]
command << " -l #{options[:limit]}" if options[:limit]
command
end

Expand Down