I need to write a script which fetched files off a ftp server and put it into a specify folder for processing.
I was used to using SSH for these job and now I was forced to connect to an SFTP server, this was my first time and everything is a little different.
I have attached the commands I used in my bash script to get the project over the line.
This command allows you get a listing of what is currently on the server.
1 |
ssh username@10.1.1.58 "ls -lha path/on/server" |
This will fetch all the CSV files on the SFTP server and copy them locally.
1 |
sftp username@$10.1.1.58:path/on/server/*.csv /data/location/ |
This was partially tricky, don’t know why. They may be an easier way which I overlooked but this worked for me. For some reason to send file you need to specify the instructions in a batch file which is execute once connected.
1 2 3 |
echo "put /path/on/server/T*.dat remote/location" > /tmp/batch.txt sftp -b /tmp/batch.txt username@10.1.1.58 rm -rf /tmp/batchfile.txt |