Skip to content

Commit

Permalink
Fix for permission denied for Put File with correct permissions (#276)
Browse files Browse the repository at this point in the history
Fixes #237
  • Loading branch information
Mihai Pârvu authored Oct 30, 2018
1 parent dc636f3 commit 602f367
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions atest/put_file.robot
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,30 @@ Putting Multiple Source Files To Single File Fails
Run Keyword And Expect Error ValueError: It is not possible to copy multiple source files to one destination file.
... Put File ${LOCAL TEXTFILES}${/}?est*.txt invalid.txt

Put File Overwrite If User In The Same Group
Put File ${LOCAL TEXTFILES}${/}${TEST FILE NAME}
SSH.File Should Exist ${TEST FILE NAME}
Add testkey User To Group test And Set Permissions
Change User And Overwrite File
Switch Connection 1
SSH.File Should Exist ${TEST FILE NAME}
[Teardown] Remove testkey User From Group test And Cleanup

*** Keywords ***
Change User And Overwrite File
Open Connection ${HOST} prompt=${PROMPT}
Login With Public Key ${KEY USERNAME} ${KEY}
Put File ${LOCAL TEXTFILES}${/}${TEST FILE NAME} ${REMOTE HOME TEST}
[Teardown] Close Connection

Add testkey User To Group test And Set Permissions
Execute Command usermod -a -G test testkey sudo=True sudo_password=test
Execute Command chmod -R 660 ${TEST FILE NAME}

Remove testkey User From Group test And Cleanup
Execute Command gpasswd -d testkey test sudo=True sudo_password=test
Execute Command rm -rf ${TEST FILE NAME}

Remove Local Temp Dir And Remote File
[Arguments] ${path}
Remove Directory ${LOCAL TMPDIR} yes
Expand Down
4 changes: 3 additions & 1 deletion src/SSHLibrary/pythonclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ def _create_missing_remote_path(self, path, mode):
return super(SFTPClient, self)._create_missing_remote_path(path, mode)

def _create_remote_file(self, destination, mode):
file_exists = self.is_file(destination)
destination = destination.encode(self._encoding)
remote_file = self._client.file(destination, 'wb')
remote_file.set_pipelined(True)
self._client.chmod(destination, mode)
if not file_exists:
self._client.chmod(destination, mode)
return remote_file

def _write_to_remote_file(self, remote_file, data, position):
Expand Down

0 comments on commit 602f367

Please sign in to comment.