Skip to content
Advertisement

Execute mirror and mget lftp commands in bash script

Current code

#!/bin/bash
SFTP_SERVER="sftp.url.com:/csv/test/10"
SFTP_USER="user"
SFTP_PWD="pwd"

## not sure if this line is needed given I specify the local directory
# in the next block of code.
cd /mnt/c/Users/user/Documents/new_directory    
lftp sftp://$SFTP_USER:$SFTP_PWD@$SFTP_SERVER
lftp -e mget *.csv mirror sftp.user.com:/csv/test/10 /mnt/c/Users/user/Documents/new_directory

Objective

Download all csv files and mirror my local directory folder with the remote server, so when the code is run again it won’t download a second file.

Error received

open: *.csv: Name or service not known

Comments

From what I understood of the lftp man page I should be able to get all wildcard files by using mget instead of the standard get, provided I use -e to use external commands. I’ve run mget manually and can download the files without issue but it doesn’t seem to support the *.csv in the script.

Appreciate any feedback you can provide as to why my code won’t download the files and what I might have misunderstood from the man pages.

Advertisement

Answer

It should be like:

lftp sftp://$SFTP_USER:$SFTP_PWD@$SFTP_SERVER -e "mget *.csv; bye"
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement