在本地缓存和sftp服务器之间同步文件

sftpsyncer的Python项目详细描述


在本地缓存和远程缓存之间逐段同步文件 SFTP服务器。

用例

您的客户机有时需要将文件同步到和 从SFTP服务器。

  • open()一个文件,不管它是远程的还是本地的。 *如果文件在本地可用,请使用本地副本。 *如果本地文件不存在,则下载它,然后使用本地副本。
  • 将()文件添加到上载包,然后push()上载所有本地排队的文件 文件夹。

这个模型很简单,如果 存在同名的文件。如果你想避免,你可能会更好 不用git之类的。

使用方法:

import sftpsyncer
from sftpsyncer import syncagent

sagent = syncagent(hostname="remote_sagenth.example.com", host_port="1222",
                username="theuser", key_path="/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"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java调用Python函数作为TEID中的UDF   java Android。支持v4导入不工作   java如何影响具有静态属性的类   java如何在从glTexImage2D()分配后编辑纹理的像素颜色   javaspringboot+rediscache+@Cacheable适用于某些方法,而不适用于其他方法   java无法将动态Web模块方面从3.0更改为2.5   java如何在新选项卡中显示打印的文档?   java Google Cloud Endpoints API方法仅在删除用户参数时成功调用   java为什么我可以使用Stack<Double>但不能使用Stack<Double>?   java JDBC PreparedStatement似乎忽略了占位符   java如何设置JInternalFrame的标准图标化位置?   Java文件。copy()不复制文件   基于另一个类的java显示arraylist?   java Android Studio:错误:非法字符:'\u2028'   对象(Java)无法实例化类型映像?   javascript错误:飞行前响应的HTTP状态代码401无效   java确保泛型vararg参数具有相同的类型