Class: Net::FTPFXP
- Inherits:
-
FTP
- Object
- FTP
- Net::FTPFXP
- Defined in:
- lib/ftpfxp/ftpfxp.rb
Overview
-
#fxpsetport
-
#fxpstor
-
#fxpretr
-
#fxpwait
-
#fxpto
-
#fastlist
-
#file_exists
-
#path_exists
Direct Known Subclasses
Instance Method Summary collapse
-
#fastlist(path = nil) ⇒ Object
This is a faster implementation of LIST where we use STAT -l on supported servers.
-
#feat ⇒ Object
Issue the
FEAT
command to dump a list of FTP extensions supported by this FTP server. -
#file_exists(path) ⇒ Object
Check if a file path exists.
-
#fxpgetpasvport ⇒ Object
Returns the
passive
port values on this ftp server. -
#fxpretr(file) ⇒ Object
This is called on the source side of the FXP.
-
#fxpsetport(ipnport) ⇒ Object
Sets the
IP
andport
for next transfer on this ftp server. -
#fxpstor(file) ⇒ Object
This is called on the destination side of the FXP.
-
#fxpto(dst, dstpath, srcpath) ⇒ Object
This FXP the specified source path to the destination path on the destination site.
-
#fxpwait ⇒ Object
This waits for the FXP to finish on the current ftp server.
-
#path_exists(path) ⇒ Object
Check if a path exists.
-
#xdupe(mode = nil) ⇒ Object
Sets the
extended dupe checking mode
on the ftp server.
Instance Method Details
#fastlist(path = nil) ⇒ Object
This is a faster implementation of LIST where we use STAT -l on supported servers. (All latest versions of ftp servers should support this!) The path argument is optional, but it will call STAT -l on the path if it is specified.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ftpfxp/ftpfxp.rb', line 160 def fastlist(path = nil) synchronize do if path.nil? putline('STAT -l') else putline("STAT -l #{path}") end return getresp end end |
#feat ⇒ Object
Issue the FEAT
command to dump a list of FTP extensions supported by this FTP server. Please note that this list is based on what the server wants to return.
46 47 48 49 50 51 |
# File 'lib/ftpfxp/ftpfxp.rb', line 46 def feat synchronize do putline('FEAT') return getresp end end |
#file_exists(path) ⇒ Object
Check if a file path exists.
174 175 176 177 178 179 180 181 182 |
# File 'lib/ftpfxp/ftpfxp.rb', line 174 def file_exists(path) resp = fastlist(path) status = false resp.each do |entry| next if '213' == entry[0,3] # Skip these useless lines. status = true if '-rw' == entry[0,3] end return status end |
#fxpgetpasvport ⇒ Object
Returns the passive
port values on this ftp server.
78 79 80 81 82 83 84 |
# File 'lib/ftpfxp/ftpfxp.rb', line 78 def fxpgetpasvport synchronize do # Get the passive IP and port values for next transfer. putline('PASV') return getresp end end |
#fxpretr(file) ⇒ Object
This is called on the source side of the FXP. This should be called after fxpstor
.
112 113 114 115 116 117 118 |
# File 'lib/ftpfxp/ftpfxp.rb', line 112 def fxpretr(file) synchronize do voidcmd('TYPE I') putline("RETR #{file}") return getresp end end |
#fxpsetport(ipnport) ⇒ Object
Sets the IP
and port
for next transfer on this ftp server.
89 90 91 92 93 94 |
# File 'lib/ftpfxp/ftpfxp.rb', line 89 def fxpsetport(ipnport) synchronize do putline("PORT #{ipnport}") return getresp end end |
#fxpstor(file) ⇒ Object
This is called on the destination side of the FXP. This should be called before fxpretr
.
100 101 102 103 104 105 106 |
# File 'lib/ftpfxp/ftpfxp.rb', line 100 def fxpstor(file) synchronize do voidcmd('TYPE I') putline("STOR #{file}") return getresp end end |
#fxpto(dst, dstpath, srcpath) ⇒ Object
This FXP the specified source path to the destination path on the destination site. Path names should be for files only. This raises an exception FTPFXPSrcSiteError
if errored on source site and raises an exception FTPFXPDstSiteError
if errored on destination site.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ftpfxp/ftpfxp.rb', line 139 def fxpto(dst, dstpath, srcpath) pline = fxpgetpasvport comp = pline.split(/\s+/) ports = String.new(comp[4].gsub('(', '').gsub(')', '')) dst.fxpsetport(ports) dst.fxpstor(dstpath) fxpretr(srcpath) resp = {} resp[:srcresp] = fxpwait raise FTPFXPTLSSrcSiteError unless '226' == resp[:srcresp][0,3] resp[:dstresp] = dst.fxpwait raise FTPFXPTLSDstSiteError unless '226' == resp[:dstresp][0,3] return resp end |
#fxpwait ⇒ Object
This waits for the FXP to finish on the current ftp server. If this is the source, it should return 226 Transfer Complete, on success. If this is the destination, it should return 226 File receive OK.
126 127 128 129 130 |
# File 'lib/ftpfxp/ftpfxp.rb', line 126 def fxpwait synchronize do return getresp end end |
#path_exists(path) ⇒ Object
Check if a path exists.
187 188 189 190 191 192 193 194 195 |
# File 'lib/ftpfxp/ftpfxp.rb', line 187 def path_exists(path) resp = fastlist(path) status = false resp.each do |entry| next if '213' == entry[0,3] # Skip these useless lines. status = true end return status end |
#xdupe(mode = nil) ⇒ Object
Sets the extended dupe checking mode
on the ftp server. If no mode specified, it returns the current mode. mode=0 : Disables the extended dupe checking mode. mode=1 : X-DUPE replies several file names per line. mode=2 : Server replies with one file name per X-DUPE line. mode=3 : Server replies with one filename per X-DUPE line with no truncation. mode=4 : All files listed in one long line up to max 1024 characters. For details, visit http://www.smartftp.com/Products/SmartFTP/RFC/x-dupe-info.txt
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ftpfxp/ftpfxp.rb', line 63 def xdupe(mode=nil) synchronize do if mode.nil? putline('SITE XDUPE') return getresp else putline("SITE XDUPE #{mode.to_i}") return getresp end end end |