Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.5k
  • 205
  • 1.8k
  • 2.3k
Source Link

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily:

#!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect "sftp>" send "lcd ~/dtc/data/outstanding\n" expect "sftp>" send "mget * \n" expect "sftp>" send "exit\n" interact 

It connects to a remote server via SFTP and downloads a bunch of files. This is working no problem, however, I want these files to appear in a certain directory on the machine (my server) running this script.

This is what I'm attempting to do on line 8 to no avail. How can I run this script via cron, and make sure it cds into the right directory on my server so that it places the downloaded files into the right directory?