I have a scenario where I have an S3 URL with binary content that needs to be transferred to an FTP server. I'm using Net::FTP
, open-uri
, and Ruby 2.0.0-p353.
require 'net/ftp'
require 'open-uri'
Net::FTP.open(x,y,z) do |ftp|
ftp.putbinaryfile(open(an_s3_url), 'remote_filename', 4096)
What the code above does is create a temporary open-uriXXYY-*
temp file in the current dir, but then hangs. I have no idea why. Interrupting the function produces the following trace:
home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:434:in `accept': Interrupt
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:434:in `transfercmd'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:543:in `block (2 levels) in storbinary'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:199:in `with_binary'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:542:in `block in storbinary'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:541:in `storbinary'
from /home/ubuntu/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/net/ftp.rb:690:in `putbinaryfile'
The workaround is to retrieve the file and then put it, but this feels clunky. Is there a reason I can't do it this way, or am I missing something obvious? Same problem with or without blocksize included.