0

I have written a script that downloads two files via sftp. In the next step I want the script to change the rights of the files. I use pysftp for downloading the files from the sever and then I use ssh.sendLine command to send the chmod command. Unfortunately this changes BOTH files to 644 instead of 600 for the cert file. If I manually type "chmod 600 key" into Terminal after running the script it changes accordingly.

I use the following code:

ssh.sendline("get file1 /home/appadmin/key")
ssh.sendline("get file2 /home/appadmin/cert")
ssh.sendline("cd /home/appadmin/")
ssh.sendline("chmod 644 cert")
ssh.sendline("chmod 600 key")
Kaiser
  • 15
  • 1
  • 5
  • Just a guess, but `cd /home/appadmin/` does not change directories like you expect. Then, there is no `cert` and `key` when you `chmod`. Use `ssh.chdir("/home/appadmin/")`. Or, skip the `cd` and use the full path to `cert` and `key`. Also see [Why doesn't “cd” work in a shell script?](https://stackoverflow.com/q/255414/608639) and [How do I change directories using Paramiko?](https://stackoverflow.com/q/8932862/608639) – jww Jul 01 '19 at 09:12
  • I just tried what you said and put in the full path in the script. Still changes both to 644. – Kaiser Jul 01 '19 at 09:21

0 Answers0