module Net::SFTP

  1. lib/net/sftp/constants.rb
  2. lib/net/sftp/errors.rb
  3. lib/net/sftp/operations/dir.rb
  4. lib/net/sftp/operations/download.rb
  5. lib/net/sftp/operations/file.rb
  6. lib/net/sftp/operations/file_factory.rb
  7. lib/net/sftp/operations/upload.rb
  8. lib/net/sftp/packet.rb
  9. lib/net/sftp/protocol/01/attributes.rb
  10. lib/net/sftp/protocol/01/base.rb
  11. lib/net/sftp/protocol/01/name.rb
  12. lib/net/sftp/protocol/02/base.rb
  13. lib/net/sftp/protocol/03/base.rb
  14. lib/net/sftp/protocol/04/attributes.rb
  15. lib/net/sftp/protocol/04/base.rb
  16. lib/net/sftp/protocol/04/name.rb
  17. lib/net/sftp/protocol/05/base.rb
  18. lib/net/sftp/protocol/06/attributes.rb
  19. lib/net/sftp/protocol/06/base.rb
  20. lib/net/sftp/protocol/base.rb
  21. lib/net/sftp/protocol.rb
  22. lib/net/sftp/request.rb
  23. lib/net/sftp/response.rb
  24. lib/net/sftp/session.rb
  25. lib/net/sftp/version.rb
  26. lib/net/sftp.rb
  27. show all
Parent: Net

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.

Methods

Public Class

  1. start

Public Class methods

start (host, user, options={}, &block)

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
[show source]
# File lib/net/sftp.rb, line 30
def self.start(host, user, options={}, &block)
  session = Net::SSH.start(host, user, options)
  sftp = Net::SFTP::Session.new(session, &block).connect!

  if block_given?
    sftp.loop
    session.close
    return nil
  end

  sftp
rescue Object => anything
  begin
    session.shutdown!
  rescue ::Exception
    # swallow exceptions that occur while trying to shutdown
  end

  raise anything
end