Automated FTP in Linux
The forums are full of people asking this honest question: how do I automate FTP upload/download so that it works from the command line without user’s intervention? But when it comes to answers, you do come back somewhat empty. Some people suggest writing their own Bash scripts, some suggest using Net::FTP, some quite rightly suggest using expect. But it seems mind boggling that in the realm of matrix-like command line consoles of Linux there’s nothing to just do the job.
I too wrote my own Bash script, my own expect script, looked at the nice interface of Net::FTP and even wanted to use PHP’s put. (Sigh). But really, it’s too much work, and it’s difficult to deploy this automated script, albeit properly written, to all the machines you want to control.
Finally, I came across lftp. Repeat after me:
LFTP is sophisticated file transfer program with command line interface. It supports FTP, HTTP, FISH, SFTP, HTTPS and FTPS protocols.
Now, how do you use it? Dramatically easy.
If you are a Fedora fellow, install it with:
su - yum -y install tftp
And, supposing the remote machine is remotemachine.com, your username is johnny, and your password is obviously secret , use this sweet syntax to get this nice fuzzy feeling of accomplishment:
# upload lftp -u johnny,secret -e "cd /home; pwd; put my-file.doc; dir; bye" remotemachine.com #download lftp -u johnny,secret -e "cd /home; pwd; get my-file.doc; bye" remotemachine.com
A big thank you to lftp developers, and hopefully their work will become common knowledge sooner.
References
|
|