Archive for October, 2017


Transfer files to FTP via Rails console

First require Net::FTP so the functions will be available

1
require 'net/ftp'

Create FTP connection, with a custom port

1
2
3
4
ftp = Net::FTP.new
ftp.connect('url', port) 
ftp.login('username', 'password')
ftp.passive = true

Move to the folder you want to upload the file into

1
ftp.chdir('folder/')

Get URL of paperclip file

1
url = 'public'+paperclip.photo.url.gsub(/\?.*/, '')

Upload to server

1
ftp.putbinaryfile(url)

Close connection

1
ftp.quit()

Permalink » No comments