Module: FileTransfer
- Defined in:
- lib/file_transfer.rb,
lib/file_transfer/ftp.rb,
lib/file_transfer/sftp.rb,
lib/file_transfer/generic.rb,
lib/file_transfer/version.rb,
lib/file_transfer/file_transfer_handler.rb
Overview
:nodoc:
Defined Under Namespace
Classes: FileTransferHandler, Ftp, Generic, Sftp
Constant Summary collapse
- VERSION =
:nodoc:
'0.0.11'
Class Method Summary collapse
- .connect(type, options) ⇒ Object
-
.download(type, options, paths) ⇒ Object
FileTransfer.download :ftp, {:username => 'foo', :password => 'bar', :host => 'localhost'}, [ {:from => "/remote/uploads/a_1.txt", :to => "/local/1.txt"}, {:from => "/remote/uploads/pdf/*.pdf", :to => "/local/pdf/"}, {:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"} ]
. - .exist?(type, options, path) ⇒ Boolean
- .list(type, options, path) ⇒ Object
- .remove(type, options, paths) ⇒ Object
- .rename(type, options, from_path, to_path) ⇒ Object
- .test_connection(type, options) ⇒ Object
-
.upload(type, options, paths) ⇒ Object
Uploads one or more files to a remote server.
Class Method Details
.connect(type, options) ⇒ Object
64 65 66 |
# File 'lib/file_transfer.rb', line 64 def self.connect(type, ) handler = FileTransferHandler.new type, end |
.download(type, options, paths) ⇒ Object
<tt>FileTransfer.download :ftp,
{:username => 'foo', :password => 'bar', :host => 'localhost'}, [
{:from => "/remote/uploads/a_1.txt", :to => "/local/1.txt"},
{:from => "/remote/uploads/pdf/*.pdf", :to => "/local/pdf/"},
{:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"}
]
</tt>
57 58 59 60 61 62 |
# File 'lib/file_transfer.rb', line 57 def self.download(type, , paths) handler = FileTransferHandler.new type, result = handler.download paths handler.close result end |
.exist?(type, options, path) ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/file_transfer.rb', line 89 def self.exist?(type, , path) handler = FileTransferHandler.new type, result = handler.exist? path handler.close result end |
.list(type, options, path) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/file_transfer.rb', line 82 def self.list(type, , path) handler = FileTransferHandler.new type, result = handler.list path handler.close result end |
.remove(type, options, paths) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/file_transfer.rb', line 68 def self.remove(type, , paths) handler = FileTransferHandler.new type, result = handler.remove paths handler.close result end |
.rename(type, options, from_path, to_path) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/file_transfer.rb', line 75 def self.rename(type, , from_path, to_path) handler = FileTransferHandler.new type, result = handler.rename from_path, to_path handler.close result end |
.test_connection(type, options) ⇒ Object
14 15 16 17 18 |
# File 'lib/file_transfer.rb', line 14 def self.test_connection(type, ) handler = FileTransferHandler.new type, handler.test_connection handler.close end |
.upload(type, options, paths) ⇒ Object
Uploads one or more files to a remote server. To upload files use the locale file paths, not the ruby class File. Types are:
-
:ftp
- for FTP file upload -
:sftp
- for SFTP file upload
Options are:
-
:username
- Specifies the username for login to the remote server -
:password
- Specifies the password for login to the remote server -
:host
- Specifies the name of the remote server. It could be a DNS name or an IP-Address these options are not necessary. -
:port
- Specifies the port of the remote server. If the remote server listen on the default port, -
:timeout
- If connection hangs, it is possible to define a timeout in seconds here, where the connection will be automatically closed.
Examples
<tt>FileTransfer.upload :ftp,
{:username => 'foo', :password => 'bar', :host => 'localhost'}, [
{:from => "/local/1.txt", :to => "/remote/uploads/a_1.txt"},
{:from => "/local/", :to => "/remote/uploads/"},
{:from => "/local/pdf/*.pdf", :to => "/remote/uploads/pdf/"},
{:from => ["/local/1.txt", "/local/2.txt", "/local/txt/*.txt"], :to => "/remote/uploads/txt/"}
]
</tt>
43 44 45 46 47 48 |
# File 'lib/file_transfer.rb', line 43 def self.upload(type, , paths) handler = FileTransferHandler.new type, result = handler.upload paths handler.close result end |