Pages

Friday, February 7, 2014

FTP made easy with LFTP

I was looking for a decent FTP client program to perform a relatively complex series of file transfers using a Linux shell script and came across LFTP.

LFTP is a freely available file transfer program which allows FTP, HTTP and a number of other connections to a remote host.

A few of the evaluation commands I tried with LFTP are listed here as a future reference to my self as well as anyone looking for quick examples.

The easiest method to connect to a FTP server using LFTP is to simply specify the URL of the host. It will open up a LFTP console which allows to perform multiple actions.


#Log into password protected FTP server
lftp -u <user name,[password]> <URL>
lftp -u myftp,mypassword 192.168.110.1

#Log into a FTP server as anonymous (if allowed)
lftp <URL>
lftp  192.168.110.1

#Once connected to the FTP server, LFTP console appears on Linux terminal.

#Create a directory
lftp <URL:/>mkdir <directory name>
lftp 192.168.110.1:/> mkdir music

#Upload a file
lftp <URL:/>put <file path>
lftp 192.168.110.1:/videos> put ./video.avi

#Download a file from FTP server
lftp <URL:/>get <file path>
ftp 192.168.110.1:/> get videos/video.avi

#Download a file from FTP server and place it in a specific local directory
lftp <URL:/>get <file path> -o <target local directory>
get videos/video.avi -o /tmp/downloads/

#List available files on a selected directory in FTP server
lftp <URL:/>ls
lftp 192.168.110.1:/> ls
drwxr-xr-x 1 ftp ftp              0 Jan 31 14:22 music
drwxr-xr-x 1 ftp ftp              0 Jan 31 14:22 videos

#Close connection
lftp 192.168.110.1:/> exit

No comments:

Post a Comment