• <bdo id='65Wzh'></bdo><ul id='65Wzh'></ul>
  • <legend id='65Wzh'><style id='65Wzh'><dir id='65Wzh'><q id='65Wzh'></q></dir></style></legend>

    <small id='65Wzh'></small><noframes id='65Wzh'>

  • <i id='65Wzh'><tr id='65Wzh'><dt id='65Wzh'><q id='65Wzh'><span id='65Wzh'><b id='65Wzh'><form id='65Wzh'><ins id='65Wzh'></ins><ul id='65Wzh'></ul><sub id='65Wzh'></sub></form><legend id='65Wzh'></legend><bdo id='65Wzh'><pre id='65Wzh'><center id='65Wzh'></center></pre></bdo></b><th id='65Wzh'></th></span></q></dt></tr></i><div id='65Wzh'><tfoot id='65Wzh'></tfoot><dl id='65Wzh'><fieldset id='65Wzh'></fieldset></dl></div>

  • <tfoot id='65Wzh'></tfoot>

      1. 如何使用 pysftp 仅同步远程目录中更改的文件?

        How to sync only the changed files from the remote directory using pysftp?(如何使用 pysftp 仅同步远程目录中更改的文件?)
      2. <tfoot id='72QYq'></tfoot>

        • <bdo id='72QYq'></bdo><ul id='72QYq'></ul>
          <legend id='72QYq'><style id='72QYq'><dir id='72QYq'><q id='72QYq'></q></dir></style></legend>
            <i id='72QYq'><tr id='72QYq'><dt id='72QYq'><q id='72QYq'><span id='72QYq'><b id='72QYq'><form id='72QYq'><ins id='72QYq'></ins><ul id='72QYq'></ul><sub id='72QYq'></sub></form><legend id='72QYq'></legend><bdo id='72QYq'><pre id='72QYq'><center id='72QYq'></center></pre></bdo></b><th id='72QYq'></th></span></q></dt></tr></i><div id='72QYq'><tfoot id='72QYq'></tfoot><dl id='72QYq'><fieldset id='72QYq'></fieldset></dl></div>

                <tbody id='72QYq'></tbody>

              <small id='72QYq'></small><noframes id='72QYq'>

                  本文介绍了如何使用 pysftp 仅同步远程目录中更改的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 pysftp 库的 get_r 函数(https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.get_r) 从 sftp 服务器获取目录结构的本地副本.

                  I am using pysftp library's get_r function (https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connection.get_r) to get a local copy of a directory structure from sftp server.

                  对于远程目录的内容已更改并且我只想获取自上次运行脚本以来更改的文件的情况,这是正确的方法吗?

                  Is that the correct approach for a situation when the contents of the remote directory have changed and I would like to get only the files that changed since the last time the script was run?

                  脚本应该能够递归同步远程目录并镜像远程目录的状态 - f.e.带有一个参数,用于控制是否应删除本地过时的文件(远程服务器上不再存在的文件),以及是否应获取对现有文件和新文件的任何更改.

                  The script should be able to sync the remote directory recursively and mirror the state of the remote directory - f.e. with a parameter controlling if the local outdated files (those that are no longer present on the remote server) should be removed, and any changes to the existing files and new files should be fetched.

                  我目前的方法就在这里.

                  示例用法:

                  from sftp_sync import sync_dir
                  
                  sync_dir('/remote/path/', '/local/path/')
                  

                  推荐答案

                  使用 pysftp.Connection.listdir_attr 获取带有属性的文件列表(包括文件时间戳).

                  Use the pysftp.Connection.listdir_attr to get file listing with attributes (including the file timestamp).

                  然后,迭代列表并与本地文件进行比较.

                  Then, iterate the list and compare against local files.

                  import os
                  import pysftp
                  import stat
                  
                  remote_path = "/remote/path"
                  local_path = "/local/path"
                  
                  with pysftp.Connection('example.com', username='user', password='pass') as sftp:
                      sftp.cwd(remote_path)
                      for f in sftp.listdir_attr():
                          if not stat.S_ISDIR(f.st_mode):
                              print("Checking %s..." % f.filename)
                              local_file_path = os.path.join(local_path, f.filename)
                              if ((not os.path.isfile(local_file_path)) or
                                  (f.st_mtime > os.path.getmtime(local_file_path))):
                                  print("Downloading %s..." % f.filename)
                                  sftp.get(f.filename, local_file_path)
                  

                  这篇关于如何使用 pysftp 仅同步远程目录中更改的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                    <i id='2WOPJ'><tr id='2WOPJ'><dt id='2WOPJ'><q id='2WOPJ'><span id='2WOPJ'><b id='2WOPJ'><form id='2WOPJ'><ins id='2WOPJ'></ins><ul id='2WOPJ'></ul><sub id='2WOPJ'></sub></form><legend id='2WOPJ'></legend><bdo id='2WOPJ'><pre id='2WOPJ'><center id='2WOPJ'></center></pre></bdo></b><th id='2WOPJ'></th></span></q></dt></tr></i><div id='2WOPJ'><tfoot id='2WOPJ'></tfoot><dl id='2WOPJ'><fieldset id='2WOPJ'></fieldset></dl></div>
                    <tfoot id='2WOPJ'></tfoot>
                    <legend id='2WOPJ'><style id='2WOPJ'><dir id='2WOPJ'><q id='2WOPJ'></q></dir></style></legend>

                        <small id='2WOPJ'></small><noframes id='2WOPJ'>

                          <tbody id='2WOPJ'></tbody>
                          • <bdo id='2WOPJ'></bdo><ul id='2WOPJ'></ul>