Skip to main content

Synchronise files between a local cache and an SFTP server

Project description

Synchronise files piecemeal back and forth between a local cache and a remote SFTP server.

Use case

You have a client that sometimes needs to syncronise files to and from an SFTP server.

  • open() a file whether it’s remote or local. * If the file is available locally, use the local copy. * If the local file doesn’t exist, download it and then use the local copy.

  • add() files to an upload package, then push() to upload all locally queued files.

This model is simplistic, and will clobber any changes at the other end if a file with the same name exists. If you want to avoid that, you may be better off using Git or the like.

How to use:

import sftpsyncer
from sftpsyncer import syncagent

sagent = syncagent(host="remote_sagenth.example.com", hostport="1222",
                username="theuser", priv_key="/home/theuser/.sagenth/key",
                local_root="/tmp/cache", remote_root="/upload_target")

# upload local files

sagent.upload_queue.add("myfile.txt")
sagent.upload_queue.add("docs/readme.txt")

sagent.push()  # upload whether or not remote files exist

# auto-get remote files, reading from cache when available

fh1 = sagent.open("myfile.txt")  # file is already local, return local fh
fh2 = sagent.open("remote.txt")  # file is not local, transfer to local cache, return local fh

# exceptions

try:
    fh3 = sagent.open("not_anywhere.txt")
except sftpsyncer.exceptions.FileNotFound as e:
    print "File does not exist on local or remote"

try:
    fh5 = sagent.open("ssh_server_unavailable.txt")
except sftpsyncer.exceptions.ConnectionError as e:
    print "Remote SFTP service appears to be unavailable"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sftpsyncer-0.1.2.tar.gz (10.6 kB view details)

Uploaded Source

File details

Details for the file sftpsyncer-0.1.2.tar.gz.

File metadata

  • Download URL: sftpsyncer-0.1.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sftpsyncer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a3bc1f2e45af69c9a24925535d232c263e65f364d0dc67ff9740ee7a3ee710b9
MD5 a8b3000388104ee9ce6db7ad664ed446
BLAKE2b-256 166b0466f5935a59df5c54f8c70ff995e089b6ef104fcb478993c14da221e279

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page