LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   Need help with lftp to automate file transfers (https://www.linuxquestions.org/questions/linux-enterprise-47/need-help-with-lftp-to-automate-file-transfers-4175658285/)

beeblequix 07-30-2019 10:05 AM

Need help with lftp to automate file transfers
 
Howdy Folks,

For the longest time I've been using a "here" statement with the old ftp program on SLES 8-11 to automate file transfers from my server to another location by calling a function similar to this in my bash scripts:

function ftp_my_file {
/usr/bin/ftp -A -n <<here
open some.ip.address
user my_username my_password
epsv4
bin
put $FILE_TO_FTP
quit
here
}

This function has worked fine up until we upgraded to SLES 12 and the old FTP program was replaced with Lftp which doesn't use the same syntax. Does someone have a method in a script using lftp that does the same thing? Thanks.

scasey 07-30-2019 10:17 AM

Quote:

Originally Posted by beeblequix (Post 6019867)
Howdy Folks,

For the longest time I've been using a "here" statement with the old ftp program on SLES 8-11 to automate file transfers from my server to another location by calling a function similar to this in my bash scripts:

function ftp_my_file {
/usr/bin/ftp -A -n <<here
open some.ip.address
user my_username my_password
epsv4
bin
put $FILE_TO_FTP
quit
here
}

This function has worked fine up until we upgraded to SLES 12 and the old FTP program was replaced with Lftp which doesn't use the same syntax. Does someone have a method in a script using lftp that does the same thing? Thanks.

Scanning the man lftp page, I don't see any difference in the syntax except, perhaps, for the syntax for epsv.
I also note that binary is the default transfer mode, but the syntax to specify that is also different in lftp.

The HERE document should continue to work once you modify the commands accordingly.

Suggest you review man lftp. It should be easy enough to convert your script.

beeblequix 07-30-2019 02:16 PM

I got it to work in my bash script --

lftp -e "set ftp:ssl-allow off; put $FILE_TO_FTP -o /fully/qualified/path/to/network/drive/$FILE_TO_FTP; bye" -u my_username,my_password some.ftpserver.local


Note 1: if I pass along the password like this and the password contains special characters then escape them.
Note 2: it's probably better to use ~/.netrc to store credentials. Will explore this.
Note 3: initially I kept getting stuck on "making data connection". The "set ftp:ssl-allow off;" part prevents it from trying to use SSL.

scasey 07-30-2019 04:03 PM

Quote:

Originally Posted by beeblequix (Post 6019936)
I got it to work in my bash script --

lftp -e "set ftp:ssl-allow off; put $FILE_TO_FTP -o /fully/qualified/path/to/network/drive/$FILE_TO_FTP; bye" -u my_username,my_password some.ftpserver.local


Note 1: if I pass along the password like this and the password contains special characters then escape them.
Note 2: it's probably better to use ~/.netrc to store credentials. Will explore this.
Note 3: initially I kept getting stuck on "making data connection". The "set ftp:ssl-allow off;" part prevents it from trying to use SSL.

.netrc is definitely the better way to go. You now not only have your password in the clear in the script, but it's probably visible in the output of a ps command while the transfer is running


All times are GMT -5. The time now is 01:00 AM.