diff --git a/README.md b/README.md index d6ebd1d..25a4e1e 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 04c2646..dea92c7 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -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" diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 00d41f7..53613bd 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -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 diff --git a/middleman-deploy.gemspec b/middleman-deploy.gemspec index b92c760..f4dbd5d 100644 --- a/middleman-deploy.gemspec +++ b/middleman-deploy.gemspec @@ -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