J
Jeff
I'm trying to use the Net::FTP class to send a text file to my FTP
server, but I don't have an actual text file to send. Instead I want
to send it a multi-line string as my "file". (I'm using Builder to
generate an XML file and I don't want to have to physically save it to
a file before sending it.)
The Net::FTP class has a method called puttextfile that seems to be
defined like this:
def puttextfile(localfile, remotefile = File.basename(localfile),
&block)
but I don't have a local filename to provide. Is there anything I can
use that would substitute for one?
I tried to use a StringIO object, hoping to use that as my
"localfile":
s = StringIO.new(xml_data)
but when I try to send it like this:
Net::FTP.open("domain.com", "username", "secret") do |ftp|
ftp.puttextfile(s, '\data\file.xml"')
end
I get this error:
TypeError: can't convert StringIO into String
from c:/ruby/lib/ruby/1.8/net/ftp.rb:571:in `open'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:571:in `puttextfile'
from (irb):33
from c:/ruby/lib/ruby/1.8/net/ftp.rb:115:in `open'
from (irb):32
Obviously it wants a filename, and I'm giving it the actual IO object
instead. .NET had the concept of IO streams, and I was hoping to use
something like that here, but I can't figure out how.
Any ideas?
Thanks!
Jeff
server, but I don't have an actual text file to send. Instead I want
to send it a multi-line string as my "file". (I'm using Builder to
generate an XML file and I don't want to have to physically save it to
a file before sending it.)
The Net::FTP class has a method called puttextfile that seems to be
defined like this:
def puttextfile(localfile, remotefile = File.basename(localfile),
&block)
but I don't have a local filename to provide. Is there anything I can
use that would substitute for one?
I tried to use a StringIO object, hoping to use that as my
"localfile":
s = StringIO.new(xml_data)
but when I try to send it like this:
Net::FTP.open("domain.com", "username", "secret") do |ftp|
ftp.puttextfile(s, '\data\file.xml"')
end
I get this error:
TypeError: can't convert StringIO into String
from c:/ruby/lib/ruby/1.8/net/ftp.rb:571:in `open'
from c:/ruby/lib/ruby/1.8/net/ftp.rb:571:in `puttextfile'
from (irb):33
from c:/ruby/lib/ruby/1.8/net/ftp.rb:115:in `open'
from (irb):32
Obviously it wants a filename, and I'm giving it the actual IO object
instead. .NET had the concept of IO streams, and I was hoping to use
something like that here, but I can't figure out how.
Any ideas?
Thanks!
Jeff