Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

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)
Comment

pysftp get-r

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

PREVIOUS NEXT
Code Example
Python :: numpy split to chunks of equal size 
Python :: how to check the version of ployly 
Python :: combining list alternatively 
Python :: color to black and white opencv 
Python :: how to make a config txt file on python 
Python :: telephone number word generator python 
Python :: p and c in python 
Python :: queryset.raw() in django rest framework joining tables 
Python :: pybind11 python37_d.dll access violation 
Python :: reorder columns in python 
Python :: python pipe select where 
Python :: installing django on windows 
Python :: max sum slice python 1 - autopilot 
Python :: pytorch pad to square 
Python :: pprint dic without sorting 
Python :: python structure like c 
Python :: python send commands in one line but write in multiple 
Python :: pycharm display info of function 
Python :: quicksort python 
Python :: python wikipedia 
Python :: rename a column 
Python :: where are python libraries installed ubuntu 
Python :: days calculator python 
Python :: convert dictionary to string 
Python :: pygame buttons 
Python :: python how to put int into list 
Python :: python libraries 
Python :: * pattern program in python 
Python :: counter method in python 
Python :: how to duplicate a row in python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =