Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

Automated FTP transfer

The lftp and the ftp commands open an interactive session with the user. We can automate FTP file transfers with a shell script:

#!/bin/bash 

#Automated FTP transfer 
HOST=example.com' 
USER='foo' 
PASSWD='password' 
lftp  -u ${USER}:${PASSWD} $HOST <<EOF 

binary 
cd /home/foo 
put testfile.jpg 

quit 
EOF 

The preceding script has the following structure:

<<EOF 
DATA 
EOF 

This is used to send data through stdin to the lftp command. The Playing with file descriptors and redirection recipe of Chapter 1, Shell Something Out, explains various methods for redirection to stdin.

The -u option logs in to the remote site with our defined USER and PASSWD. The binary command sets the file mode to binary.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985