Class: Net::FTPFXP
- Inherits:
-
FTP
- Object
- FTP
- Net::FTPFXP
- Defined in:
- lib/ftpfxp/ftpfxp.rb
Overview
-
#fxpsetport
-
#fxpstor
-
#fxpretr
-
#fxpwait
-
#fxpto
-
#fastlist
-
#fileExists
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
FEATcommand to dump a list of FTP extensions supported by this FTP server. -
#fileExists(path) ⇒ Object
Check if a file path exists.
-
#fxpgetpasvport ⇒ Object
Returns the
passiveport values on this ftp server. -
#fxpretr(file) ⇒ Object
This is called on the source side of the FXP.
-
#fxpsetport(ipnport) ⇒ Object
Sets the
IPandportfor 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.
-
#xdupe(mode = nil) ⇒ Object
Sets the
extended dupe checking modeon 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.
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ftpfxp/ftpfxp.rb', line 158 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.
45 46 47 48 49 50 |
# File 'lib/ftpfxp/ftpfxp.rb', line 45 def feat synchronize do putline('FEAT') return getresp end end |
#fileExists(path) ⇒ Object
Check if a file path exists.
172 173 174 175 176 177 178 179 180 |
# File 'lib/ftpfxp/ftpfxp.rb', line 172 def fileExists(path) resp = fastlist(path) stats = false resp.each do |entry| next if '213' == entry[0,3] # Skip these useless lines. status = true if '-rw' == entry[0,3] end return resp end |
#fxpgetpasvport ⇒ Object
Returns the passive port values on this ftp server.
77 78 79 80 81 82 83 |
# File 'lib/ftpfxp/ftpfxp.rb', line 77 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.
111 112 113 114 115 116 117 |
# File 'lib/ftpfxp/ftpfxp.rb', line 111 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.
88 89 90 91 92 93 |
# File 'lib/ftpfxp/ftpfxp.rb', line 88 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.
99 100 101 102 103 104 105 |
# File 'lib/ftpfxp/ftpfxp.rb', line 99 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.
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ftpfxp/ftpfxp.rb', line 138 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 = fxpwait raise FTPFXPSrcSiteError unless '226' == resp[0,3] resp = dst.fxpwait raise FTPFXPDstSiteError unless '226' == resp[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.
125 126 127 128 129 |
# File 'lib/ftpfxp/ftpfxp.rb', line 125 def fxpwait synchronize do return getresp end 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
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ftpfxp/ftpfxp.rb', line 62 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 |