Answers for "pysftp get-r"

0

pysftp get-r

# pysftp get_r does not work on Windows. 
# It uses os.sep and os.path functions for remote SFTP paths, what is wrong, as SFTP paths always use a forward slash.
# But you can easily implement a portable replacement:

import os
from stat import S_ISDIR, S_ISREG
Posted by: Guest on October-09-2021
0

pysftp get-r

def get_r_portable(sftp, remotedir, localdir, preserve_mtime=False):
    for entry in sftp.listdir_attr(remotedir):
        remotepath = remotedir + "/" + entry.filename
        localpath = os.path.join(localdir, entry.filename)
        mode = entry.st_mode
        if S_ISDIR(mode):
            try:
                os.mkdir(localpath)
            except OSError:     
                pass
            get_r_portable(sftp, remotepath, localpath, preserve_mtime)
        elif S_ISREG(mode):
            sftp.get(remotepath, localpath, preserve_mtime=preserve_mtime)
Posted by: Guest on October-09-2021
0

pysftp get-r

get_r_portable(sftp, '/abc/def/ghi/klm/mno', 'C:\\pqr', preserve_mtime=False)
Posted by: Guest on October-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language