Skip to content Skip to sidebar Skip to footer

Getting Permissionerror While Downloading Files To Local Machine From Sftp Server Using Pysftp

I'm unable to copy files from SFTP server. I'm getting the permission error. I have tried changing the mode in os.mkdirs() function. sftp = pysftp.Connection(host = myhostname, use

Solution 1:

The localpath argument of pysftp Connection.get method is a path to a file, where the downloaded contents should be stored to.

The output in your localpath is a folder, not a file.

You need to append a filename to the path.

englishlocalpath = localpath + '\\output_ts_2020'+fweek+'_English_EU.txt'
sftp.get(remotepath=englishpath, localpath=englishlocalpath)

Alternatively, change the local working directory to localpath and you can omit the localpath argument. pysftp will download the file to the working directory, keeping the original name (taken from the remotepath argument):

os.chdir(localpath)

sftp.get(remotepath=englishpath)
sftp.get(remotepath=chinapath)
sftp.get(remotepath=japanpath)
sftp.get(remotepath=koreapath)

Post a Comment for "Getting Permissionerror While Downloading Files To Local Machine From Sftp Server Using Pysftp"