Skip to main content
https://travis-ci.org/codebynumbers/ftpretty.png?branch=master https://coveralls.io/repos/codebynumbers/ftpretty/badge.png?branch=master https://img.shields.io/pypi/v/ftpretty.svg https://img.shields.io/pypi/dm/ftpretty.svg

A wrapper for simple FTP operations: get, put, list etc.

The goal of this library is to provide a frictionless experience to FTPing files in way similar to Amazon’s s3cmd command line tool. The API should be intuitive with the order of arguments reflecting the transfer direction of bytes.

Transfers are assumed to be binary.

Unrecognized commands fall through to the underlying FTP or FTP_TLS connection object

Supports python 2 & 3, tested on 2.7 & 3.5, 3.6, & 3.7

Examples

from ftpretty import ftpretty

# Minimal
f = ftpretty(host, user, pass)

# Advanced
# kwargs are passed to underlying FTP or FTP_TLS connection
# secure=True argument switches to an FTP_TLS connection default is False
# passive=False disable passive connection, True is the default
# Note: port is not supported as an argument in underlying FTP or FTP_TLS but support for
# handling port has been internally added in ftpretty by setting FTP.port or FTP_TLS.port
f = ftpretty(host, user, pass, secure=True, passive=False, timeout=10, port=2121)

# Get a file, save it locally
f.get('someremote/file/on/server.txt', '/tmp/localcopy/server.txt')

# Get a file and write to an open file
myfile = open('/tmp/localcopy/server.txt', 'wb')
f.get('someremote/file/on/server.txt', myfile)

# Get a file and return contents (in python 3 contents is bytes)
contents = f.get('someremote/file/on/server.txt')

# Get a tree on a remote directory (similar to shutil.copytree, without following symlinks
f.get_tree("/remote/tree/on/server", "/tmp/local/tree")

# Put a local file to a remote location
# non-existent subdirectories will be created automatically
f.put('/tmp/localcopy/data.txt', 'someremote/file/on/server.txt')

# Put a local file into a remote directory, denoted by trailing slash on remote
f.put('/tmp/localcopy/data.txt', 'someremote/dir/')

# Put using an open file desciptor
myfile = open('/tmp/localcopy/data.txt', 'r')
f.put(myfile,  'someremote/file/on/server.txt')

# Put using string data (in python 3 contents should be bytes)
f.put(None,  'someremote/file/greeting.txt', contents='blah blah blah')

# Put a tree on a remote directory (similar to shutil.copytree, without following symlinks
f.put_tree("Local/tree", "/remote/files/server")

# Return a list the files in a directory
f.list('someremote/folder')
['a.txt', 'b.txt']

f.list('someremote/folder', extra=True)
[{'date': 'Feb 11',
  'datetime': datetime.datetime(2014, 2, 11, 2, 3),
  'directory': 'd',
  'group': '1006',
  'items': '3',
  'name': 'a.txt',
  'owner': '1005',
  'perms': 'rwxr-xr-x',
  'size': '4096',
  'time': '02:03',
  'year': '2014'},
 {'date': 'Feb 11',
  'datetime': datetime.datetime(2014, 2, 11, 2, 35),
  'directory': 'd',
  'group': '1006',
  'items': '3',
  'name': 'b.txt',
  'owner': '1005',
  'perms': 'rwxr-xr-x',
  'size': '4096',
  'time': '02:35',
  'year': '2014'}]

# Change to remote directory
f.cd('someremote/folder')

# Create directory
f.mkdir('new_folder')

# Delete a remote file
f.delete('someremote/folder/file.txt')

# Close the connection
f.close()

Changelog for ftpretty

0.4.0 (2021-06-12)
  • added get_tree command

  • rewrote MockFTP for test to use in-memory filesystem

0.3.5 (2021-02-03)
  • bugfixes for directory listing time parsing

0.3.4 (2020-10-01)
  • mkdir() added

0.3.3 (2020-07-27)
  • parse alternate directory listing format

0.3.1 (2019-12-01)
  • accept port argument

0.3.0 (2019-10-21)
  • permissions parsing fix, upload tree fix

0.2.4 (2016-12-14)
  • upload_tree() added

0.2.3 (2015-12-01)

  • rename() added

0.2.2 (2015-07-23)

  • Setup fix

0.2.1 (2015-05-20)

  • Python3 support added

0.2.0 (2014-11-28)

  • Fixed an edge case for list

  • PEP 8 fixes

0.1.9 (2014-06-17)

  • Support for Python 2.6

0.1.8 (2014-04-08)

  • Add ability to filter dotfiles from directory list

0.1.7 (2014-03-03)

  • Add tests

0.1.6 (2014-02-17)

  • Parse file dates in list(extra=True) into datetime objects

  • add dateutil dependency

  • Add tests and mock FTP client

  • Reformat authors file

  • Some more examples

  • Pep8ify

0.1.5 (2014-02-17)

  • Version bump for PyPI

0.1.4 (2014-02-17)

  • History fix

0.1.3 (2014-02-17)

  • Add passive flag

0.1.2 (2014-02-13)

  • Initial release.

Authors

  • Rob Harrigan

  • Chris Cannon

  • Philippe Ombredanne

  • Panos Katseas

  • Niklas Bivald

  • Doug Van Horn

  • Oz N Tiram

  • pratham2003

  • Mouckeytou Moulongui

  • Veniamin Stepanov

Metadata

Release files for ftpretty 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ftpretty 0.4.0
File Size Uploaded
ftpretty-0.4.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ftpretty 0.4.0
File Interpreter ABI Platform
ftpretty-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.2 kB

Release files / ftpretty-0.4.0.tar.gz

Download URL ftpretty-0.4.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
61233b9212f2cceec96ee2c972738fa31cae7248e92d0874c99c04ee739bb5a9
BLAKE2b-256 checksum
How to use checksums
a2c5f5ed409312f67697bf7967cd52ed74794ccb860fec29d2105470c987de09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

Release files / ftpretty-0.4.0-py2.py3-none-any.whl

Download URL ftpretty-0.4.0-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1c0c45bacf69b82827838ae9b77a66e48064d2686649628e647965a85aa7367a
BLAKE2b-256 checksum
How to use checksums
9bd1cbd3736da8d6253da85838b105b97bc794965584243711fa2ef0bb585df3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

1 release file

0.3.1

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

2 release files

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page