Create a temporary file with Tempfile and upload from that : FTP Client « Network « Ruby






Create a temporary file with Tempfile and upload from that


require 'net/ftp'
require 'tempfile'

tempfile = Tempfile.new('test')

my_data = "This is some text data I want to upload via FTP."
tempfile.puts my_data

ftp = Net::FTP.new('ftp.domain.com')
ftp.passive = true
ftp.login
ftp.chdir('/your/folder/name/here')

ftp.puttextfile(tempfile.path, 'my_data')

ftp.close
tempfile.close

 








Related examples in the same category

1.File Transfers with FTP
2.Connecting to an FTP server with net/ftp using an FTP URL is a simple operation:
3.Net::FTP provides a login method that you can use against a Net::FTP object, like so:
4.if a username and password are required, use this code:
5.use the chdir method:
6.change to any directory in the remote filesystem:
7.Ftp mkdir
8.delete and rename files
9.Set the mode to passive
10.Downloading Files
11.prints a string to the screen whenever another 100 kilobytes of the file have been downloaded.
12.Uploading Files
13.keep the user informed of the progress of the upload.