class Middleman::Deploy::Methods::Ftp
Attributes
host[R]
pass[R]
path[R]
port[R]
user[R]
Public Class Methods
new(server_instance, options = {})
click to toggle source
Calls superclass method
Middleman::Deploy::Methods::Base::new
# File lib/middleman-deploy/methods/ftp.rb, line 10 def initialize(server_instance, options = {}) super(server_instance, options) @host = self.options.host @user = self.options.user @pass = self.options.password @path = self.options.path @port = self.options.port end
Public Instance Methods
process()
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 20 def process puts "## Deploying via ftp to #{self.user}@#{self.host}:#{self.path}" ftp = open_connection Dir.chdir(self.server_instance.build_dir) do filtered_files.each do |filename| if File.directory?(filename) upload_directory(ftp, filename) else upload_binary(ftp, filename) end end end ftp.close end
Protected Instance Methods
filtered_files()
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 40 def filtered_files files = Dir.glob('**/*', File::FNM_DOTMATCH) files.reject { |filename| filename =~ Regexp.new('\.$') } end
handle_exception(exception, ftp, filename)
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 46 def handle_exception(exception, ftp, filename) reply = exception.message err_code = reply[0, 3].to_i if err_code == 550 if File.binary?(filename) ftp.putbinaryfile(filename, filename) else ftp.puttextfile(filename, filename) end end end
open_connection()
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 59 def open_connection ftp = Net::FTP.new(self.host) ftp.login(self.user, self.pass) ftp.chdir(self.path) ftp.passive = true ftp end
upload_binary(ftp, filename)
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 68 def upload_binary(ftp, filename) begin ftp.putbinaryfile(filename, filename) rescue Exception => exception handle_exception(exception, ftp, filename) end puts "Copied #{filename}" end
upload_directory(ftp, filename)
click to toggle source
# File lib/middleman-deploy/methods/ftp.rb, line 78 def upload_directory(ftp, filename) begin ftp.mkdir(filename) puts "Created directory #{filename}" rescue end end