Class: SftpWrapper::Curl
- Inherits:
-
Object
- Object
- SftpWrapper::Curl
- Defined in:
- lib/sftp_wrapper/curl.rb
Overview
The wrapper for curl.
Constant Summary collapse
- CURL_ERRORS =
lookup table of curl errors.
{ # URL malformed. The syntax was not correct. 3 => SftpWrapper::Errors::ConnectionError, # Couldn't resolve proxy. The given proxy host could not be resolved. 5 => SftpWrapper::Errors::ConnectionError, # Couldn't resolve host. The given remote host was not resolved. 6 => SftpWrapper::Errors::ConnectionError, # Failed to connect to host. 7 => SftpWrapper::Errors::ConnectionError, # The user name, password, or similar was not accepted and curl failed to log in. 67 => SftpWrapper::Errors::AuthenticationFailure, # The resource referenced in the URL does not exist. 78 => SftpWrapper::Errors::ResourceNotExist, }.freeze
Instance Attribute Summary collapse
-
#curl_args ⇒ Object
readonly
Returns the value of attribute curl_args.
-
#curl_path ⇒ Object
readonly
Returns the value of attribute curl_path.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#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, options = {}) ⇒ Curl
constructor
Initialize SFTP wrapper.
-
#upload(source, destination) ⇒ Object
Put local file.
Constructor Details
#initialize(host, port, username, password, options = {}) ⇒ Curl
Initialize SFTP wrapper.
38 39 40 41 42 43 44 45 |
# File 'lib/sftp_wrapper/curl.rb', line 38 def initialize(host, port, username, password, = {}) @host = host @port = port @username = username @password = password @curl_path = [:curl_path] || 'curl' @curl_args = [:curl_args] || [] end |
Instance Attribute Details
#curl_args ⇒ Object (readonly)
Returns the value of attribute curl_args.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def curl_args @curl_args end |
#curl_path ⇒ Object (readonly)
Returns the value of attribute curl_path.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def curl_path @curl_path end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/sftp_wrapper/curl.rb', line 10 def username @username end |
Instance Method Details
#download(source, destination) ⇒ Object
Get remote file.
55 56 57 58 59 60 61 |
# File 'lib/sftp_wrapper/curl.rb', line 55 def download(source, destination) userinfo = [username, password].map(&ERB::Util.method(:url_encode)).join(':') uri = URI::Generic.build(scheme: 'sftp', userinfo: userinfo, host: host, port: port, path: source) cmd = %W[#{curl_path} -o #{destination}] + curl_args + [uri.to_s] execute(*cmd) end |
#upload(source, destination) ⇒ Object
Put local file.
71 72 73 74 75 76 77 |
# File 'lib/sftp_wrapper/curl.rb', line 71 def upload(source, destination) userinfo = [username, password].map(&ERB::Util.method(:url_encode)).join(':') uri = URI::Generic.build(scheme: 'sftp', userinfo: userinfo, host: host, port: port, path: destination) cmd = %W[#{curl_path} -T #{source}] + curl_args + [uri.to_s] execute(*cmd) end |