Is there a Rake task for FTP?

I am looking for a Rake task to deploy via FTP.

Does anyone know anyone?

Anders

+3
source share
3 answers

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
+5
source

It’s not that I knew that Net :: SFTP is good, you can write a new rake task to do what you would rather easily.

It also depends on what kind of deployment you are doing - if its Rails, did you view Capistrano or Vlad Deployment ?

+4
source

Source: https://habr.com/ru/post/1702632/


All Articles