Net::SFTP is a pure-Ruby module for programmatically interacting with a remote host via the SFTP protocol (that‘s SFTP as in "Secure File Transfer Protocol" produced by the Secure Shell Working Group, not "Secure FTP" and certainly not "Simple FTP").
See Net::SFTP#start for an introduction to the library. Also, see Net::SFTP::Session for further documentation.
A convenience method for starting a standalone SFTP session. It will start up an SSH session using the given arguments (see the documentation for Net::SSH::Session for details), and will then start a new SFTP session with the SSH session. This will block until the new SFTP is fully open and initialized before returning it.
sftp = Net::SFTP.start("localhost", "user") sftp.upload! "/local/file.tgz", "/remote/file.tgz"
If a block is given, it will be passed to the SFTP session and will be called once the SFTP session is fully open and initialized. When the block terminates, the new SSH session will automatically be closed.
Net::SFTP.start("localhost", "user") do |sftp| sftp.upload! "/local/file.tgz", "/remote/file.tgz" end
# File lib/net/sftp.rb, line 30 30: def self.start(host, user, options={}, &block) 31: session = Net::SSH.start(host, user, options) 32: sftp = Net::SFTP::Session.new(session, &block).connect! 33: 34: if block_given? 35: sftp.loop 36: session.close 37: return nil 38: end 39: 40: sftp 41: rescue Object => anything 42: begin 43: session.shutdown! 44: rescue Exception 45: # swallow exceptions that occur while trying to shutdown 46: end 47: 48: raise anything 49: end
A convenience method for starting a standalone SFTP session. It will start up an SSH session using the given arguments (see the documentation for Net::SSH::Session for details), and will then start a new SFTP session with the SSH session. This will block until the new SFTP is fully open and initialized before returning it.
sftp = Net::SFTP.start("localhost", "user") sftp.upload! "/local/file.tgz", "/remote/file.tgz"
If a block is given, it will be passed to the SFTP session and will be called once the SFTP session is fully open and initialized. When the block terminates, the new SSH session will automatically be closed.
Net::SFTP.start("localhost", "user") do |sftp| sftp.upload! "/local/file.tgz", "/remote/file.tgz" end
# File lib/net/sftp.rb, line 30 30: def self.start(host, user, options={}, &block) 31: session = Net::SSH.start(host, user, options) 32: sftp = Net::SFTP::Session.new(session, &block).connect! 33: 34: if block_given? 35: sftp.loop 36: session.close 37: return nil 38: end 39: 40: sftp 41: rescue Object => anything 42: begin 43: session.shutdown! 44: rescue Exception 45: # swallow exceptions that occur while trying to shutdown 46: end 47: 48: raise anything 49: end