added FTP deployment

master
Benjamin Knofe 2012-11-08 16:45:57 +01:00
parent 2b33d3d409
commit 817ac132c0
4 changed files with 68 additions and 3 deletions

View File

@ -95,6 +95,22 @@ To use a particular branch, add:
Default is `gh-pages`. Run `git branch -a` to see a list of possible
branches.
### Step 4c - FTP setup
#### These settings are required.
Edit `config.rb`, and add:
activate :deploy do |deploy|
deploy.method = :ftp
deploy.host = "ftp.example.com"
deploy.user = "tvaughan"
deploy.password = "secret"
deploy.path = "/srv/www/site"
end
Adjust these values accordingly.
### Step 5
middleman build [--clean]

View File

@ -140,6 +140,54 @@ EOF
orig.remote(remote).fetch
end
def deploy_ftp
require 'net/ftp'
require 'ptools'
host = self.deploy_options.host
user = self.deploy_options.user
pass = self.deploy_options.password
path = self.deploy_options.path
puts "## Deploying via ftp to #{user}@#{host}:#{path}"
ftp = Net::FTP.new(host)
ftp.login(user, pass)
ftp.chdir(path)
ftp.passive = true
Dir.chdir('build/') do
Dir['**/*'].each do |f|
if File.directory?(f)
begin
ftp.mkdir(f)
rescue
puts "Folder '#{f}' exists. skipping..."
end
else
begin
if File.binary?(f)
ftp.putbinaryfile(f, f)
else
ftp.puttextfile(f, f)
end
rescue Exception => e
reply = e.message
err_code = reply[0,3].to_i
if err_code == 550
if File.binary?(f)
ftp.putbinaryfile(f, f)
else
ftp.puttextfile(f, f)
end
end
end
end
end
end
ftp.close
end
end
# Alias "d" to "deploy"

View File

@ -5,7 +5,7 @@ require "middleman-core"
module Middleman
module Deploy
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :path, :clean, :remote, :branch, :after_build); end
class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build); end
class << self

View File

@ -16,10 +16,11 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
# The version of middleman-core your extension depends on
s.add_runtime_dependency("middleman-core", [">= 3.0.0"])
# Additional dependencies
s.add_runtime_dependency("git", "~> 1.2.0")
s.add_runtime_dependency("ptools")
end