Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


ST: Added :copy_via variable to :copy strategy in order to :scp or :sftp (default) to the remote machines #115

merged 1 commit into from

4 participants



I've added the variable :copy_via for the :copy strategy in order to define how to move the tar/zip across to the remote machines. One of my clients does not support :sftp so we're using :scp instead.

Would be nice to have it in the official repo. Many thanks.



This looks like a great addition. I too would like this feature to be implemented into the distro. For now I'll have to be happy with a hand mod :/


@rudionrails Would it be possible to remove the modifications to the unit tests altogether, since nothing would fail in their absence? This change looks simple enough that I can merge it without the tests. Also, would you mind removing the spaces after and before the parentheses?


@carsomyr When changing this line:

upload(filename, remote_filename, :via => configuration[:copy_via] || :sftp)

I had to amend the existing tests, since most of them are mocks/expectations that fail when not provding the :via option, e.g.

@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
#=> fail

@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz", :via => sftp)
#=> OK

If you do not want the existing tests to being touched, I've amended my commit and made the changes unobtrusive.

@leehambley leehambley merged commit db1bdae into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. @rudionrails

    ST: Added :copy_via variable to :copy strategy in order to :scp or :s…

    rudionrails authored
    …ftp (default) to the remote machines
This page is out of date. Refresh to see the latest.
10 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -39,6 +39,11 @@ module Strategy
# :zip, and which specifies how the source should be compressed for
# transmission to each host.
+ # By default, files will be transferred across to the remote machines via 'sftp'. If you prefer
+ # to use 'scp' you can set the :copy_via variable to :scp.
+ #
+ # set :copy_via, :scp
+ #
# There is a possibility to pass a build command that will get
# executed if your code needs to be compiled or something needs to be
# done before the code is ready to run.
@@ -316,7 +321,10 @@ def decompress_remote_file
# Distributes the file to the remote servers
def distribute!
- upload(filename, remote_filename)
+ args = [filename, remote_filename]
+ args << { :via => configuration[:copy_via] } if configuration[:copy_via]
+ upload(*args)
21 test/deploy/strategy/copy_test.rb
@@ -197,6 +197,27 @@ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
+ def test_deploy_with_copy_via_should_use_the_given_transfer_method
+ @config[:copy_via] = :scp
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ Dir.expects(:chdir).yields
+ @source.expects(:checkout).returns(:local_checkout)
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz", {:via => :scp})
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+ @strategy.deploy!
+ end
def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
@config[:copy_cache] = true
Something went wrong with that request. Please try again.