Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Simple FTP Deploy Script
- #Pushes all file changes by a specific git commit
- #Defaults to last commit
- require 'rubygems'
- require 'net/ssh'
- require 'net/sftp'
- path = "/"
- ftp_host = 'ftp.example.com'
- ftp_user = 'username'
- ftp_password = 'secret'
- def upload(options={})
- Net::SSH.start(options[:ftp_host],options[:ftp_user],:password =>options[:ftp_password] ) do |ssh|
- ssh.sftp.connect do |sftp|
- total = files.size
- options[:files].each_with_index do |file,index|
- from = file
- to = "#{options[:path]}/#{file}"
- begin
- remote_dir = File.dirname(to)
- sftp.upload!(from,to)
- rescue Net::SFTP::StatusException => e
- raise unless e.code == 2
- mkdir(sftp,remote_dir)
- sftp.upload!(from,to)
- else
- puts "#{index+1} of #{total} Uploading #{to}"
- end
- end
- end
- end
- end
- def mkdir(sftp,remote_dir)
- begin
- sftp.mkdir!(remote_dir, :permissions => 0755)
- rescue Net::SFTP::StatusException => e
- raise unless e.code == 2
- mkdir(sftp,File.dirname("#{remote_dir}.dir"))
- sftp.mkdir!(remote_dir, :permissions => 0755)
- end
- end
- commit = ''
- ARGV.each do |var|
- if var =~ /^([\w]{5,40})/
- commit = $1.strip
- break
- end
- end
- updated_file_names = `git show #{commit} --name-only`
- files = updated_file_names.split(/\n/)
- files = lines[5..-1].reject {|v| v.strip.empty? }
- puts "Ready to upload the following..."
- puts
- files.each {|file| puts file }
- puts
- puts "#{lines.size} files waiting to be pushed..."
- print "Proceed? "
- y_or_no = STDIN.gets
- if y_or_no.match(/^y/i)
- puts "Uploading..."
- upload(:path => path,:files => files,:ftp_host => ftp_host,:ftp_user=>ftp_user,:ftp_password=>ftp_password)
- else
- puts "Quiting"
- end
Add Comment
Please, Sign In to add comment