使用
pysftp.Connection.listdir_attr来获取具有属性(包括文件时间戳记)的文件列表。
然后,迭代列表并与本地文件进行比较。
import osimport pysftpimport statremote_path = "/remote/path"local_path = "/local/path"with pysftp.Connection('example.com', username='username', password='password') 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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)