Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Copying and syncing extension to Net::FTP

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.mdown

FTPExt

A simple gem for copying, synching, and deleting entire folders over FTP. Adds two new public methods to Net::FTP — put_dir and rmrf_dir. put_dir takes a hash of arguments:

  • local - (string) The relative or absolute path to the local directory to be copied.
  • remote - (string) The relative or absolute remote path that the local directory will be copied to.
  • verbose - (bool: defaults to false) Will output progress if set to true.
  • erase - (bool: defaults to false) If set to true, put_dir will overwrite any existing directories (default behavior is to update changed files only).
  • exclude - (array) A list of any files in local directory to be excluded. All file paths in exclude should be relative to local

rmrf_dir takes two arguments: the path to the remote directory to be deleted, and a verbose boolean flag (defaulted to false).

Usage

To use FTPExt, require it and use Net::FTP as normal. Because FTPExt requires Net::FTP for you, you don't need to include it separately.

require 'rubygems'
require 'ftp-ext'

ftp = Net::FTP.new('ftp/server/address')
ftp.login('username', 'password')

ftp.put_dir(:local => 'path/to/local', :remote => 'path/to/remote')

For example, imagine I have a local directory, /Users/zpendleton/code, that I want to upload on my server to the /home/zpendleton directory. I'd run the following command:

ftp.put_dir('/Users/zpendleton/code', '/home/zpendleton/code')

If the code directory already exists in /home/zpendleton, it will be updated (the script checks the last modified timestamps of all files). If the code directory doesn't exist, it will be created. To overwrite the code directory on the server, set the :erase option in put_dir to true.

To later delete the /home/zpendleton/code directory (in verbose mode), you would use:

ftp.rmrf_dir('/home/zpendleton/code', true)

To leave verbose mode turned off, you would just omit the second parameter.

Contributing

  1. Fork the project.
  2. Create a branch (git checkout -b my_edit).
  3. Commit your changes (git commit -am "Added feature").
  4. Push to the branch (git push origin my_edit).
  5. Create an issue with a link to your branch.
  6. Kick it old school to this while you wait.

Copyright

Copyright (c) 2010 Zach Pendleton. See LICENSE for details.

Something went wrong with that request. Please try again.