Class: Net::FTPFXP

Inherits:
FTP
  • Object
show all
Defined in:
lib/ftpfxp/ftpfxp.rb

Direct Known Subclasses

FTPFXPTLS

Instance Method Summary collapse

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.



111
112
113
114
115
116
117
118
119
120
# File 'lib/ftpfxp/ftpfxp.rb', line 111

def fastlist(path = nil)
	synchronize do
		if path.nil?
		  putline('STAT -l')
		else
		  putline("STAT -l #{path}")
		end
		return getresp
	end
end

#featObject

Issue the FEAT command to dump a list of FTP extensions supported by this FTP server.



17
18
19
20
21
22
# File 'lib/ftpfxp/ftpfxp.rb', line 17

def feat
	synchronize do
		putline('FEAT')
		return getresp
	end
end

#fileExists(path) ⇒ Object

Check if a file path exists.



123
124
125
126
127
128
129
130
131
# File 'lib/ftpfxp/ftpfxp.rb', line 123

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

#fxpgetpasvportObject

Returns the passive port values on this ftp server.



45
46
47
48
49
50
51
# File 'lib/ftpfxp/ftpfxp.rb', line 45

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.



73
74
75
76
77
78
79
# File 'lib/ftpfxp/ftpfxp.rb', line 73

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.



54
55
56
57
58
59
# File 'lib/ftpfxp/ftpfxp.rb', line 54

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.



63
64
65
66
67
68
69
# File 'lib/ftpfxp/ftpfxp.rb', line 63

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.



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ftpfxp/ftpfxp.rb', line 93

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 "#{resp}" unless '226' == resp[0,3]
	resp = dst.fxpwait
	raise "#{resp}" unless '226' == resp[0,3]
	return resp
end

#fxpwaitObject

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.



85
86
87
88
89
# File 'lib/ftpfxp/ftpfxp.rb', line 85

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 www.smartftp.com/Products/SmartFTP/RFC/x-dupe-info.txt



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ftpfxp/ftpfxp.rb', line 32

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