usa ims
usa ims

Reputation: 145

Permissions denied renaming file with pysftp module

I'm new to Python and I writing a script that uses the pysftp module. There is one function in the pysftp module that I'm having trouble with -- it's the rename function.

Here is the call

srv = pysftp.Connection(host = 'xxx.com', username = 'xxx', password = 'xxx')             
y = srv.rename('ftptest.txt', 'renamedfile.txt')

The error I'm getting is

Traceback (most recent call last):
   File "./ftp.py", line 49, in <module>
    y = srv.rename('ftptest.txt', 'renamedfile.txt')
   File "/usr/local/lib/python2.7/dist-packages/pysftp.py", line 740, in rename
self._sftp.rename(remote_src, remote_dest)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 365, in     rename
     self._request(CMD_RENAME, oldpath, newpath)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 729, in _request
    return self._read_response(num)
    File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 776, in _read_response
self._convert_status(msg)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 804, in    _convert_status
raise IOError(errno.EACCES, text)
IOError: [Errno 13] Permission denied

I have verified that the file exists and it has the 777 for permissions.

Upvotes: 1

Views: 2345

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202138

  1. With SFTP protocol (which lacks concept of a current working directory), using an absolute paths is recommended. With a relative path, the result is server implementation specific. So you cannot be sure what files you are actually trying to rename.

  2. On *nix systems, to rename a file, you need write permissions to a containing folder. The permissions to the file you are renaming do not matter.

Upvotes: 1

Related Questions