Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'gmail'
- require 'net/ftp'
- local_path = "tmp"
- def ftp_to_bluehost(file)
- ftp_user = "user@domain.com"
- ftp_pass = "pass"
- ftp_host = "ftp.domain.com"
- ftp_port = 21
- remote_file_path = "remote"
- ftp = Net::FTP.new
- ftp.connect(ftp_host,ftp_port)
- ftp.login(ftp_user,ftp_pass)
- ftp.mkdir(remote_file_path) if ftp.ls.include?(remote_file_path)
- ftp.chdir(remote_file_path)
- ftp.putbinaryfile(file)
- ftp.close
- end
- def get_bluehost_file(file, local_path)
- ftp_user = "user@domain.com"
- ftp_pass = "pass"
- ftp_host = "ftp.domain.com"
- ftp_port = 21
- remote_file_path = "remote"
- ftp = Net::FTP.new
- ftp.connect(ftp_host,ftp_port)
- ftp.login(ftp_user,ftp_pass)
- ftp.chdir(remote_file_path)
- ftp.getbinaryfile(file, "tmp/#{file}")
- ftp.close
- end
- def delete_tmp_dir(local_path)
- Dir.foreach(local_path) { |file| puts file; File.delete("#{local_path}/#{file}") unless file == "." || file == ".."}
- end
- #working in 1.9.3
- gmail = Gmail.connect('user@gmail.com', 'pass')
- gmail.inbox.emails.each do |email|
- email.message.attachments.each do |f|
- f.filename.match(/[\w+-_ ]+.(\w{3})/)
- puts "extension for #{f.filename} is #{$1}"
- File.write(File.join(local_path, f.filename), f.body.decoded)
- ftp_to_bluehost(File.join(local_path, f.filename))
- delete_tmp_dir(local_path)
- get_bluehost_file(f.filename, "#{local_path}/#{f.filename}")
- end
- end
- gmail.logout
Add Comment
Please, Sign In to add comment