How can I change the permissions of the file/command, while using the sftp command via a shell script? My sftp connection is established, but it fails while executing the chmod command.

As of now, I am using chmod 775, which exits without creating proper permissions in the target directory.

  • Is there any error message? what is the login used to connect ? what is the result of ls -l filename via sftp? what is the result and error message if you do it manually? Could you edit the Question and provide this information? – Jay jargot May 15 '16 at 21:13
  • You say that you're using sftp in the context of a shell script. How are you passing the commands to sftp? If you're using the -b switch, I cannot replicate your problem; I have successfully used it to upload a file and change its permissions. – DopeGhoti May 15 '16 at 21:14
  • 1) the only error message i receive is invalid command. the command, i pass through the script is quote site chmod 750 $file.txt, after the put command. The put is successful. When, i do it manually, i am not receiving any error. It is successful. Only when done via script it errors me out. there are 2 files i ftp and both are able to be sftp'ed. – Sravani May 16 '16 at 14:55
  • I am passing the commands via a script. I am not using the -b. I specified all the parameters in the script first and then pass the parameters in the command.The only commands i used in the script is sftp username@hostname put file1 put file 2 quote site chmod 775 file 1 quote site chmod 775 file 2 is there any other command i have to use, when i am doing the sftp and trying to do chmod. – Sravani May 16 '16 at 14:57
  • sftp username@hostname put file1 put file2 quote site chmod 750 ${file1} quote site chmod 750 ${file2} quit EOF – Sravani May 16 '16 at 15:01
  • Change the permission for the file at your end before connecting to server via SFTP, same as how you want to write permissions at server
  • Connect to server via SFTP
  • use -p option in put sftp> put -p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.