Hi,
I'm looking for a Rake task to do deployment via FTP.
Does anyone know of any?
Anders
Hi,
I'm looking for a Rake task to do deployment via FTP.
Does anyone know of any?
Anders
Not that I know of though the Net::SFTP gem is pretty nice, you can write a new rake task pretty easily to do what you would like.
It also depends on what kind of deployment you're doing - if its Rails, have you looked into Capistrano or Vlad the Deployer?
Ok, I decided to do it myself. The code is not very beautiful since it contains a lot of exception handling, but it gets the job done :)
require 'rake'
require 'net/ftp'
def ftp_files(prefixToRemove, sourceFileList, targetDir, hostname, username, password)
Net::FTP.open(hostname, username, password) do |ftp|
begin
puts "Creating dir #{targetDir}"
ftp.mkdir targetDir
rescue
puts $!
end
sourceFileList.each do |srcFile|
if prefixToRemove
targetFile = srcFile.pathmap(("%{^#{prefixToRemove},#{targetDir}}p"))
else
targetFile = srcFile.pathmap("#{targetDir}%s%p")
end
begin
puts "Creating dir #{targetFile}" if File.directory?(srcFile)
ftp.mkdir targetFile if File.directory?(srcFile)
rescue
puts $!
end
begin
puts "Copying #{srcFile} -> #{targetFile}" unless File.directory?(srcFile)
ftp.putbinaryfile(srcFile, targetFile) unless File.directory?(srcFile)
rescue
puts $!
end
end
end
end
task :ftp => [:dist] do
ftp_files("dist", FileList["dist/**/*"], "remote_dir", 'host.com', 'user', 'pwd')
end