I'm trying to copy files from SFTP server . I can connect using python pysftp . I can run:
data = srv.listdir()
for i in data:
print I
And I get the Directory list. But when I try
sftp.put (localpath,"file_name.txt")
I get
>"IOError: [Errno 13] Permission denied: 'C:\\....."
I have permission to that folder, because I can run MKDIR and it creates a directory in that file path. I have tried many many different ways but no luck so far, any help is truly appreciated.
import pysftp
import os
def sftpExample():
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection('HOST', username='username', password='Password', cnopts=cnopts) as sftp :
print 'connected '
localpath="C:\\new project\\new"
remotepath="/folder1"
sftp.put(localpath,"infso.txt")
sftp.put(localpath,remotepath)
sftp.getfo (remotepath, localpath )
srv.get_r(localpath, remotepath)
srv.close()
sftpExample()
I get this error code:
Traceback (most recent call last):
File "db_backup.py", line 42, in <module>
sftpExample()
File "db_backup.py", line 17, in sftpExample
sftp.put(localpath,"GT-Dallas SFTP infso.txt")
File "c:\Python27\lib\site-packages\pysftp\__init_.py", line 364, in put
confirm=confirm)
File "c:\Python27\lib\site-packages\paramiko\sftp_client.py", line 720, in put
with open(localpath, 'rb') as fl:
IOError: [Errno 13] Permission denied: "C:\\new project\\new"
I've tried all different ways to copy the file as you see however I've had no luck so far.
The issue is that you're trying to save a file as a directory which, at least in my experience, is what throws the Permission Denied
error in pysftp
.
Change this line of code:
localpath="C:\\new project\\new"
To this:
localpath="C:\\new project\\new\\infso.txt"
NOTE: infso.txt
can be anything you want to name the local file being downloaded. I've used the same name here as the remote file's name from your example for symmetry and simplicity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With