“pysftp get-r” Código de respuesta

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)
Stupid Salmon

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
Stupid Salmon

pysftp get-r

get_r_portable(sftp, '/abc/def/ghi/klm/mno', 'C:\\pqr', preserve_mtime=False) 
Stupid Salmon

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código