May 2017
Beginner
552 pages
28h 47m
English
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.