-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Bug reports
I tried to set permission on a file on a SFTP server. I use normally use FileZilla to interact with the server, but I needed a fast way to change a lot of files, file permission. So I thought I would write a python script.
I noticed 2 things, if I only have read access to the file, I could not change the permission, giving me a ssh2.exceptions.SFTPProtocolError
, I can using the same login, change the permission in FileZilla.
The second and more important issue, was that I could not change the permission at all using the code described below:
Steps to reproduce:
def chmod(sftp, path, permissions):
stat = sftp.stat(path)
print("original permission", oct(stat.permissions))
stat.permissions = permissions | 0x8000 #I tried without the '|' as well, and I tried with only LIBSSH2_SFTP_S_IRWXU
print("seting permissions to ", oct(stat.permissions))
try:
if sftp.setstat(path, stat) == 0:
stat = sftp.stat(path)
print("managed to set permissions to ", oct(stat.permissions))
else:
print("failed to set permissions")
except Exception:
raise
The out put is this when trying to change the permission of a file from '666' to '755'
original permission 0o100666
seting permissions to 0o100755
managed to set permissions to 0o100666
success
Expected behaviour:
I expect that I can change permission on files with only read-access, as long as the authenticated user, has privileges todo so
I expected that the new file permission would be '755' after calling setstat
with changed permissions
Actual behaviour:
When I only read access has been set on a file it throws a ssh2.exceptions.SFTPProtocolError
When trying to setstat it does not change, even though the setstat()
returned a 0
Additional info:
I am uncertain of which libssh2 I am running, as I just pip installed ssh2-python
and it was up and running, but if I were to hazard a guess, I'd say 1.9.0