Skip to content

Repository files navigation

FtpSync

CI

A simple library for synchronizing from/to FTP servers.

Installation

Add this line to your application's Gemfile:

gem'ftpsync'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ftpsync

Usage

example=FtpSync::Simple.new"ftp.example.com","username","password"example.pull_dir('remotepath','localpath')

Options

FtpSync::Simple#new accepts an options hash:

OptionDefaultDescription
:port21FTP port to connect to
:passivefalseUse passive mode
:verbosefalseLog progress to stderr

FtpSync::Simple#pull_dir accepts an options hash:

OptionDescription
:sinceSkip files that already exist locally and are up to date
:skip_errorsRescue Net::FTPPermError and continue instead of raising

Note::since compares size and the mtime reported by the server's LIST output, which usually has minute precision. A remote file of the same size that was modified within the same minute as the local copy may therefore be skipped.

Passing a block to pull_dir invokes it with the local path of each downloaded file:

example.pull_dir('remotepath','localpath',since: true)do |file|
process(file)end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake to run the tests and RuboCop (or rake test / rake rubocop individually). You can also run bin/console for an interactive prompt that will allow you to experiment.

Integration tests (requires Docker)

The integration suite runs against a real FTP server (garethflowers/ftp-server, vsftpd) in a Docker container:

$ rake test:integration

The container listens on 127.0.0.1:2121 (control) and 127.0.0.1:40000-40009 (passive data). The tests are skipped automatically if Docker is not available, and the container is created and removed for each run. Override the credentials and control port with the FTPSYNC_TEST_USER, FTPSYNC_TEST_PASS and FTPSYNC_TEST_FTP_PORT environment variables.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/quintasan/ftpsync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Credits

This gem is a basically stripped down version of orlando/ftp_sync which I couldn't get to work.

About

A simple library for synchronizing from/to FTP servers

Resources

Code of conduct

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages