/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'net/ftp' require 'fileutils' include FileUtils #creates dir cd( "/Users/user/Folder/" ) dirc = Time.now.strftime("%Y%B%d") Dir.mkdir( dirc , 0700 ) cd( "/Users/user/Folder/" + dirc) ftp = Net::FTP.new('ftp.example.com') # run the script like # ruby ftp.rb username password ftp.login(user=ARGV[0], ARGV[1]) files = ftp.chdir('/OUTGOING') files = ftp.nlst('*') puts "File list obtained... #{files}" files.each do |fname| puts "Downloading file #{fname}" ftp.getbinaryfile(fname, fname) # uncomment the next two lines if you want to delete the files after download #puts "Deleting file #{fname}" #ftp.delete(fname) end ftp.close
Comments
