Ok, I decided to do it myself. The code is not very beautiful, since it contains a lot of exception handling, but it does its job :)
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
source
share