On Mar 20, 10:40 am, “ChrisKaelin” [email protected] wrote:
- ftpfxp library is targeted on fxp transfers, but it connects ok -
Try net/sftp Module. With that I made a backup script on window$ using
scp and/or sftp, because rsync is not available on the server, I have
to back up.
net/sftp project:http://raa.ruby-lang.org/project/net-sftp/
Unfortunately, sftp is a different protocol than FTPS and that module
probably won’t help.
(3 months ago I received a spec saying my company would communicate
with another company using SFTP, only to figure out after code had
been written that they meant FTPS.)
I looked in my install of ruby and found a file net/ftptls.rb. That
code looks like it’s only for Implicit FTPS, not explicit. I’d try it
anyway.
The code I ended up writing (in Java) was a class that interfaced to
the curl command line client. It worked very well. As dirty as it
seemed at the time, I still think it was better than writing JNI to
the curl C interface.
Here is a quick and dirty class to interface to the curl command line
client from ruby. This should work for FTPS, if your curl client was
compiled with it. curl -V will list the protocols it supports.
class CurlFtp
CURL = “curl”
def initialize(url, user, pass, verbose=false)
@url = url
@user = user
@pass = pass
@verboseFlag = (verbose) ? ‘-v’ : ‘’
end
def put(path, &block)
command = sprintf “‘%s’ %s --upload-file - --user ‘%s:%s’ ‘%s/
%s’”,
CURL, @verboseFlag, @user, @pass, @url, path
IO.popen(command, “w”, &block)
raise “Curl error: #{$?.to_i / 256}” if $? != 0
end
def get(path, &block)
command = sprintf “‘%s’ %s --user ‘%s:%s’ ‘%s/%s’”,
CURL, @verboseFlag, @user, @pass, @url, CGI.escape(path)
IO.popen(command, “r”, &block)
raise “Curl error: #{$?.to_i / 256}” if $? != 0
end
end
ftp = CurlFtp.new(‘ftp://localhost:21’, ‘bcastill’, ‘pass’, false)
ftp.put(‘/upload/file.txt’) do |io|
io.puts(“Writing to FTP server…”)
end
puts “Getting data:”
ftp.get(‘/upload/file.txt’) do |io|
io.each_line do |line|
puts “LINE: #{line}”
end
end