Class: SftpWrapper::OpenSSH
- Inherits:
-
Object
- Object
- SftpWrapper::OpenSSH
- Defined in:
- lib/sftp_wrapper/open_ssh.rb
Overview
The wrapper for OpenSSH’s sftp command.
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
Default value of open timeout.
10
- DEFAULT_READ_TIMEOUT =
Default value of read timeout.
10
- DEFAULT_COMMAND_TIMEOUT =
Default value of command timeout.
9_999_999
- DEFAULT_SSH_OPTIONS =
Default value of ssh options
{ PasswordAuthentication: 'yes', PreferredAuthentications: 'password', PubkeyAuthentication: 'no', NumberOfPasswordPrompts: 1, StrictHostKeyChecking: 'no', UserKnownHostsFile: '/dev/null', TCPKeepAlive: 'yes', ServerAliveInterval: 60, ServerAliveCountMax: 3, }.freeze
- DEFAULT_SSH_CONFIG =
Default value of ssh config file path.
'/dev/null'
- PASSWORD_PROMPT_RE =
pattern of password prompt.
/ password: /.freeze
- SFTP_PROMPT =
sftp prompt.
'sftp> '
- SFTP_PROMPT_RE =
pattern of sftp prompt.
/^#{SFTP_PROMPT}/.freeze
Instance Attribute Summary collapse
-
#command_timeout ⇒ Object
readonly
Returns the value of attribute command_timeout.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#ssh_config ⇒ Object
readonly
Returns the value of attribute ssh_config.
-
#ssh_options ⇒ Object
readonly
Returns the value of attribute ssh_options.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#download(source, destination) ⇒ Object
Get remote file.
-
#initialize(host, port, username, password, ssh_options: {}, ssh_config: DEFAULT_SSH_CONFIG, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, command_timeout: DEFAULT_COMMAND_TIMEOUT, debug: false) ⇒ OpenSSH
constructor
Initialize SFTP wrapper.
-
#upload(source, destination) ⇒ Object
Put local file.
Constructor Details
#initialize(host, port, username, password, ssh_options: {}, ssh_config: DEFAULT_SSH_CONFIG, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, command_timeout: DEFAULT_COMMAND_TIMEOUT, debug: false) ⇒ OpenSSH
Initialize SFTP wrapper.
rubocop:disable Metrics/ParameterLists
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 62 def initialize(host, port, username, password, ssh_options: {}, ssh_config: DEFAULT_SSH_CONFIG, open_timeout: DEFAULT_OPEN_TIMEOUT, read_timeout: DEFAULT_READ_TIMEOUT, command_timeout: DEFAULT_COMMAND_TIMEOUT, debug: false) @host = host @port = port @username = username @password = password @ssh_options = DEFAULT_SSH_OPTIONS.merge() @ssh_config = ssh_config @open_timeout = open_timeout @read_timeout = read_timeout @command_timeout = command_timeout @debug = debug end |
Instance Attribute Details
#command_timeout ⇒ Object (readonly)
Returns the value of attribute command_timeout.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def command_timeout @command_timeout end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def debug @debug end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def host @host end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def open_timeout @open_timeout end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def port @port end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def read_timeout @read_timeout end |
#ssh_config ⇒ Object (readonly)
Returns the value of attribute ssh_config.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def ssh_config @ssh_config end |
#ssh_options ⇒ Object (readonly)
Returns the value of attribute ssh_options.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def @ssh_options end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 10 def username @username end |
Instance Method Details
#download(source, destination) ⇒ Object
Get remote file.
91 92 93 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 91 def download(source, destination) execute(%W[get #{source} #{destination}].shelljoin) end |
#upload(source, destination) ⇒ Object
Put local file.
104 105 106 |
# File 'lib/sftp_wrapper/open_ssh.rb', line 104 def upload(source, destination) execute(%W[put #{source} #{destination}].shelljoin) end |