Class: FileTransfer::Sftp
Instance Attribute Summary collapse
-
#sftp ⇒ Object
readonly
Returns the value of attribute sftp.
Attributes inherited from Generic
#host, #keys, #password, #port, #timeout_seconds, #username
Instance Method Summary collapse
- #close ⇒ Object
-
#download(from_path, to_path) ⇒ Object
Downloads data from SFTP server.
-
#initialize(options = {}) ⇒ Sftp
constructor
A new instance of Sftp.
-
#list(path) ⇒ Array<String>
Gets directory listing from SFTP server.
-
#open_connection(conn_timeout = timeout_seconds) { ... } ⇒ Object
Opens new connection, if not already open.
-
#remove(path) ⇒ Object
Deletes file / folder from SFTP server.
-
#rename(from_path, to_path) ⇒ Object
Moves file / folder from SFTP server.
-
#upload(from_path, to_path) ⇒ Object
Uploads data to SFTP server.
Methods inherited from Generic
Constructor Details
#initialize(options = {}) ⇒ Sftp
Returns a new instance of Sftp.
8 9 10 11 |
# File 'lib/file_transfer/sftp.rb', line 8 def initialize( = {}) [:port] ||= 22 super() end |
Instance Attribute Details
#sftp ⇒ Object (readonly)
Returns the value of attribute sftp.
6 7 8 |
# File 'lib/file_transfer/sftp.rb', line 6 def sftp @sftp end |
Instance Method Details
#close ⇒ Object
57 58 59 |
# File 'lib/file_transfer/sftp.rb', line 57 def close # do nothing end |
#download(from_path, to_path) ⇒ Object
Downloads data from SFTP server
16 17 18 19 20 |
# File 'lib/file_transfer/sftp.rb', line 16 def download(from_path, to_path) open_connection do sftp.download! from_path, to_path end end |
#list(path) ⇒ Array<String>
Gets directory listing from SFTP server
34 35 36 37 38 |
# File 'lib/file_transfer/sftp.rb', line 34 def list(path) open_connection(60) do sftp.dir.entries path end end |
#open_connection(conn_timeout = timeout_seconds) { ... } ⇒ Object
Opens new connection, if not already open
64 65 66 67 68 69 |
# File 'lib/file_transfer/sftp.rb', line 64 def open_connection(conn_timeout = timeout_seconds) connect if closed? timeout(conn_timeout) do yield if block_given? end end |
#remove(path) ⇒ Object
Deletes file / folder from SFTP server
42 43 44 45 46 |
# File 'lib/file_transfer/sftp.rb', line 42 def remove(path) open_connection(60) do sftp.remove! path end end |
#rename(from_path, to_path) ⇒ Object
Moves file / folder from SFTP server
51 52 53 54 55 |
# File 'lib/file_transfer/sftp.rb', line 51 def rename(from_path, to_path) open_connection(60) do sftp.rename! from_path, to_path end end |
#upload(from_path, to_path) ⇒ Object
Uploads data to SFTP server
25 26 27 28 29 |
# File 'lib/file_transfer/sftp.rb', line 25 def upload(from_path, to_path) open_connection do sftp.upload! from_path, to_path end end |