How to write an binary file to ftp

Net::FTP#putbinaryfile(binary_file, remotefile)

binary_file is not a local file from some directory,but a dynamic
generation from codes.

The above codes not work,how to write it to ftp?

ftp api itself has binary mode ,but not support writing file which
itself is initially binary data?

My server does not support filesystem writing,so i can not store the
binary_file data as an image in the file directory,and then send the
image using Net::FTP#putbinaryfile method.
Could i send the binary_file directly using
Net::FTP#putbinaryfile(binary_file, remotefile)?

thanks,Fred.
But i get the ftppermerror when using storbinary and StringIO.
########
Net::FTP.open(‘showreelfinder.com’) do |ftp|
ftp.passive=true
ftp.login(name,password)
ftp.chdir(‘www.showreelfinder.com/web/site/temp/uploads/heywatch
/thumbnails’)

 thumbnail_file=StringIO.new(thumbnail)
 ftp.storbinary("STOR"+"#{thumb_title}",thumbnail_file,1024)

end
###########
The thumbnail is binary file,so can i use the stringio?
can you tell me the details? I can not find an good example in ruby
document.
Thank you very much!

On Nov 8, 9:27 am, Guo Y. [email protected]
wrote:

My server does not support filesystem writing,so i can not store the
binary_file data as an image in the file directory,and then send the
image using Net::FTP#putbinaryfile method.
Could i send the binary_file directly using
Net::FTP#putbinaryfile(binary_file, remotefile)?

Looking at the source to net/ftp it doesn’t look like putbinaryfile
can do that, however all putbinaryfile seems to do is open up the file
and pass it to storbinary, presumably you could pass any IO object (eg
a StringIO) to storbinary.

Fred

are you sure the specified user can upload files
yes,i am sure

########
Net::FTP.open(‘showreelfinder.com’) do |ftp|
� � � ftp.passive=true
� � � ftp.login(name,password)
� � � ftp.chdir(‘www.showreelfinder.com/web/site/temp/uploads/heywatch
� � � � � � � � � � � � � � � � � � � � � � � � � � � � � �/thumbnails’)

� � �thumbnail_file=StringIO.new(thumbnail)
� � �ftp.storbinary(“STOR”+“#{thumb_title}”,thumbnail_file,1024)

Looks like you are missing a space after STOR,
thank,i will try.
you should probably
also make the chdir and absolute path.
I am sure the following path is right
www.showreelfinder.com/web/site/temp/uploads/heywatch/thumbnails
Fred

On Nov 8, 2:47 pm, Guo Y. [email protected]
wrote:

thanks,Fred.
But i get the ftppermerror when using storbinary and StringIO.

are you sure the specified user can upload files

########
Net::FTP.open(‘showreelfinder.com’) do |ftp|
ftp.passive=true
ftp.login(name,password)
ftp.chdir(‘www.showreelfinder.com/web/site/temp/uploads/heywatch
/thumbnails’)

 thumbnail_file=StringIO.new(thumbnail)
 ftp.storbinary("STOR"+"#{thumb_title}",thumbnail_file,1024)

Looks like you are missing a space after STOR, you should probably
also make the chdir and absolute path.

Fred

On Nov 8, 3:48 pm, Guo Y. [email protected]
wrote:

thumbnail_file=StringIO.new(thumbnail)

do i need to change the above like this?Because i think the thumbnail is
binary file.

If you’ve got a string ruby doesn’t care about what’s in it (of course
exactly what that line should depends on what kind of object you
have). You wouldn’t get a permission error if you got that wrong
though - you’d probably just upload junk

Fred

If you’ve got a string ruby doesn’t care about what’s in it (of course
exactly what that line should depends on what kind of object you
have). You wouldn’t get a permission error if you got that wrong
though - you’d probably just upload junk

hi fred

After add a blank character and change thumbnail to thumbnail.to_s,my
project works now.Thank you very much.

thumbnail_file=StringIO.new(thumbnail)

do i need to change the above like this?Because i think the thumbnail is
binary file.

thumbnail_file=StringIO.new(thumbnail.to_s)