Cobra Forum

Linux => New to Ubuntu => Topic started by: mahesh on Aug 14, 2023, 03:46 AM

Title: Ubuntu 20.04 Bash Script
Post by: mahesh on Aug 14, 2023, 03:46 AM
Hi all

I am hoping someone can help with this script I am trying to create. I am posting this here as this is the first time I have tried to create a script and could do with some pointers / syntax help.

The scenario is this - I need to write a script which will be run as a cronjob to download a couple of files from a suppliers SFTP server. I have to authenticate with a password, so what I came up with was this - which works from the command line - but not as a script;

     Code:
#!/bin/bashsftp [username]@[sftp server address]
get FILE1.ZIP /var/www/datafiles/
cd DIRECTORY2
get FILE2.ZIP /var/www/datafiles/
bye

I then saved it and used

     Code:
chmod +x filename.sh
so it could be called.

Obviously this is far too simple as, I dont think you can connect to SFTP in the way you can with FTP (ftp [password]:[username]@[ftp server address]) - also while the first line opens a connection to the SFTP server and prompts for a password, the next lines are not passed as commands to the connected server... so, is anyone able to help with some pointers?

Many thanks in advance