Class: XFTP::Session::FTP Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
FTP session adapter
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#chdir(path) ⇒ Object
private
Changes the current (remote) working directory.
-
#directory?(path) ⇒ Boolean
private
a directory on the remote host.
-
#download(from, to: File.basename(from), block_size: Net::FTP::DEFAULT_BLOCKSIZE) ⇒ Object
private
Initiates a download from remote to local, synchronously.
-
#each_file ⇒ Object
private
Calls the block once for each entry in the current directory on the remote server and yields a filename to the block.
-
#each_io ⇒ Object
private
Calls the block once for each entry in the current directory on the remote server and yields a filename and ‘StringIO` object to the block.
-
#entries(pattern = nil) ⇒ Array<String>
private
An array of entries (including directories) in the remote directory.
-
#exists?(dirname) ⇒ Boolean
private
‘true` if the argument refers to a directory on the remote host.
-
#file?(path) ⇒ Boolean
private
a file on the remote host.
-
#files ⇒ Array<String>
private
An array of filenames in the remote directory.
-
#get(filename) ⇒ StringIO
private
Downloads file into IO object.
- #glob(pattern, &callback) ⇒ Object private
-
#initialize(uri, settings = {}) ⇒ FTP
constructor
private
Creates an FTP session adapter instance.
-
#mkdir(dirname) ⇒ Object
private
Creates a remote directory.
-
#move(from, to:) ⇒ Object
private
Renames (moves) a file on the server.
-
#rmdir(dirname) ⇒ Object
private
Removes the remote directory.
Methods inherited from Base
Methods included from Helpers::Logging
Methods included from DSL::BlockEvaluator
Constructor Details
#initialize(uri, settings = {}) ⇒ FTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates an FTP session adapter instance
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/xftp/session/ftp.rb', line 15 def initialize(uri, settings = {}) super @ftp = Net::FTP.new @port = settings.delete(:port) || uri.port || Net::FTP::FTP_PORT @credentials[:login] ||= 'anonymous' = XFTP.config.ftp.deep_merge(@settings) .each { |key, val| @ftp.public_send("#{key}=", val) } end |
Instance Method Details
#chdir(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Changes the current (remote) working directory
28 29 30 31 |
# File 'lib/xftp/session/ftp.rb', line 28 def chdir(path) ensure_relative_path! :chdir, path @ftp.chdir path end |
#directory?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
a directory on the remote host
58 59 60 61 62 63 64 65 |
# File 'lib/xftp/session/ftp.rb', line 58 def directory?(path) ensure_relative_path! :directory?, path chdir path chdir '..' true rescue false end |
#download(from, to: File.basename(from), block_size: Net::FTP::DEFAULT_BLOCKSIZE) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initiates a download from remote to local, synchronously
112 113 114 115 |
# File 'lib/xftp/session/ftp.rb', line 112 def download(from, to: File.basename(from), block_size: Net::FTP::DEFAULT_BLOCKSIZE) log "downloading file from #{from} to #{to}..." @ftp.get(from, to, block_size) end |
#each_file ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Calls the block once for each entry in the current directory on the remote server and yields a filename to the block
83 84 85 |
# File 'lib/xftp/session/ftp.rb', line 83 def each_file files.each { |filename| yield filename } end |
#each_io ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Calls the block once for each entry in the current directory on the remote server and yields a filename and ‘StringIO` object to the block
89 90 91 92 93 94 |
# File 'lib/xftp/session/ftp.rb', line 89 def each_io each_file do |filename| io = get filename yield filename, io end end |
#entries(pattern = nil) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of entries (including directories) in the remote directory.
125 126 127 |
# File 'lib/xftp/session/ftp.rb', line 125 def entries(pattern = nil) @ftp.nlst pattern end |
#exists?(dirname) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns ‘true` if the argument refers to a directory on the remote host.
49 50 51 |
# File 'lib/xftp/session/ftp.rb', line 49 def exists?(dirname) entries.include? dirname end |
#file?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
a file on the remote host
69 70 71 |
# File 'lib/xftp/session/ftp.rb', line 69 def file?(path) !directory?(path) end |
#files ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of filenames in the remote directory.
118 119 120 |
# File 'lib/xftp/session/ftp.rb', line 118 def files entries.select { |entry| file? entry } end |
#get(filename) ⇒ StringIO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Downloads file into IO object
98 99 100 |
# File 'lib/xftp/session/ftp.rb', line 98 def get(filename) @ftp.getbinaryfile(filename, nil) end |
#glob(pattern, &callback) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 |
# File 'lib/xftp/session/ftp.rb', line 103 def glob(pattern, &callback) Operations::FTP::Glob.new(@ftp).call(pattern, &callback) end |
#mkdir(dirname) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a remote directory
36 37 38 39 |
# File 'lib/xftp/session/ftp.rb', line 36 def mkdir(dirname) ensure_relative_path! :mkdir, dirname @ftp.mkdir dirname end |
#move(from, to:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Renames (moves) a file on the server
76 77 78 79 |
# File 'lib/xftp/session/ftp.rb', line 76 def move(from, to:) log "moving from #{from} to #{to}..." @ftp.rename(from, to) end |
#rmdir(dirname) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the remote directory
43 44 45 46 |
# File 'lib/xftp/session/ftp.rb', line 43 def rmdir(dirname) ensure_relative_path! :rmdir, dirname @ftp.rmdir dirname end |