1

I am able to zip and transfer files using SFTP with the below commands from my script:

zipfilename="Order_$(date +"%Y%m%d%H%M%S").zip"
echo "Start Execution" $(date +"%Y%m%d%H%M%S") >> "$logfile"
echo "Zipping Files" >> "$logfile"
zip $zipfilename order*.xml
echo "Zipping Success" >> "$logfile"
echo "put $zipfilename In" | sshpass -p $PSWRD sftp user@xxx.xxx.com >> "$logfile"

Below is the result:

sftp> put Order_20190830221440.zip In
Uploading Order_20190830221440.zip to /In/Order_20190830221440.zip

I am able to confirm that the zipped file is getting transferred successfully. However, when I try to unzip it via SFTP I get an error. I am using the below commands:

echo "unzip $zipfilename" | sshpass -p $PSWRD sftp user@xxx.xxx.com >> "$logfile"

The error is as follows:

sftp> unzip Order_20190830221440.zip
Invalid command.

I've tried this both for zip and tar approaches.
Any idea what the issue might be?

1

You cannot unzip a file on a remote server with SFTP. That's just not possible.


If you have a shell access to the server, you can unzip the file using shell:

sshpass -p $PSWRD ssh User@xxx.xxx.com unzip $zipfilename

As you do not seem to have a shell access, then unless you have yet another access (like some web-based control panel), you won't be able to unzip the file on the server.

  • i tried that but it came back with Request failed: Non SCP Command: unzip – Migs Isip Aug 30 '19 at 12:57
  • i think this is the right track, it just needs to have sshpass -p $PSWRD ssh User@xxx.xxx.com 'unzip $zipfilename' – Migs Isip Aug 30 '19 at 12:59
  • 1
    So does it work with the quotes? You should not need them. They will actually prevent resolution of the zipfilename. It rather looks like you do not have a shell access. Or do you? – Martin Prikryl Aug 30 '19 at 13:22
  • sorry yes you're correct, it didn't work. How do I determine if I have shell access? – Migs Isip Aug 30 '19 at 13:31
  • 1
    Yes it looks like you do not. Unless you have yet another access (like some web based control panel), you won't be able to unzip the file on the server. – Martin Prikryl Aug 30 '19 at 13:49

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.