Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python paramiko giving error "Permission denied [Errno 13]" on windows server on using sftp

trying to download some files from windows server using sftp in paramiko. get method is:

def get(self, remotepath, localpath = None):
    """Copies a file between the remote host and the local host."""
    if not localpath:
        localpath = os.path.split(remotepath)[1]
    self._sftp_connect()
    self._sftp.get(remotepath, localpath)

On running the script as sshObj.get('C:\\my_file.txt', 'D:\\python\\'), it throws the error :

 File "C:\Py34\lib\site-packages\paramiko\sftp_client.py", line 806, in _convert_status
raise IOError(errno.EACCES, text)`PermissionError: [Errno 13] **Permission denied**`

I have given all the permissions to the folder. also shared it with other users. But still the error is there. Any leads if anyone has faced this before will be helpful.

Note: I installed freesshd to make my localbox an ssh server.

like image 472
Pankaj Avatar asked Dec 05 '22 04:12

Pankaj


2 Answers

It is not about the path naming convention. In the local path, you did not mention the file name, you have just mentioned the directory to save the file. Use: sshObj.get('C:\\my_file.txt', 'D:\\python\\my_file.txt') instead of sshObj.get('C:\\my_file.txt', 'D:\\python\\')

like image 171
Shubhojyoti Ganguly Avatar answered Dec 06 '22 18:12

Shubhojyoti Ganguly


Thanks All! Finally I found the answer. It was because of the format of the filepaths.

On trying sshObj.get("/remote_file.txt","C:/tmp/local_file.txt") it succeded without any error.

Download the tool winSCP, it has a good GUI which will help you understand the format of file paths properly.

Also check your base SFTP folder on the remote machine because in my case the error was thrown because remote_file.txt was not located at the root sftp folder(which can be configured manually) on the remote box.

like image 26
Pankaj Avatar answered Dec 06 '22 19:12

Pankaj