Friday, July 30, 2010

lftp is a well-known ftp client. I use it with both MacOSX and Grml Linux.

Few days ago I had to download all files from a virtual host directory which resides in a shared hosting environment. A bad thing about using these cheap shared hostings is that it provides us ftp to be the only mean of file transferring which sucks. (When possible, I would rather go with sftp, rsync or fully shell access where there are a whole bunch of other fancy ways to choose from.)

I searched on Google to find any alternative ways (other than lftp) to sync files from ftp site to my local directory instead of having to download the whole files again and again which is too expensive. (By synchronizing I mean to fetch only newer or modified files on the next synchronizations.) (which lftp's man page does not state precisely whether it can do it or not so I assume it can't.) Unfortunately, I couldn't find an OpenSource one for Linux. I could see only proprietary softwares for both Windows and Linux. If anyone can suggest me for Linux, please do. I know WinSCP for Windows is free-to-use and supports synchronization but I need one for Linux.

OK. So it seemed I had no other choices. I had to go with lftp to download the whole files to my local disk then.

As usual, I logged on to the ftp server with lftp, switched to the directory I wanted (in my case it was public_html/), then issued "mirror" command. Unfortunately, I got this error:

[Delaying before reconnect: 57]

I then pressed ctrl+c and tried "ls" and this is what I got:

[lftp 4.0.2] someuser@somehost ~ % ls

`ls' at 0 [Delaying before reconnect: 57]

I was like #wtf (oops!). I then turned debugging mode of lftp on. With the error message I got from running lftp in debugging mode, I then found out (from Google) that if I ran into that mysterious problem, I should try:

set ftp:ssl-allow no

And it just worked....! Now I can use both mirror and ls and assumably everything... ha ha

Note that as I am just a lazy nerd so I didn't go further to find out why we need to unset that ssl-allow property : P I would greatly appreciate if anyone can tell me why : )

thing is, if you want to use ssl/tls (switching it off wasnt a solution for me), you either have to activate passive mode or use active mode.

with passive mode it should work just fine (usually used if you're behind a nat..). if you want to use active, you have to configure portmaps on your router and write your internet ip in the lftp config.

lftp can only fetch new files with the following operators:--only-newer --ignore-timetherefore, to download only new file:mirror --only-newer --ignore-timeYou can exclude folders as well, lets say you are doing an upload, but want to ignore your assets folder, and only upload new files:mirror -R --only-newer --ignore-time --exclude ASSETS/

To connect using plain ftp, the following is a one liner:lftp -e "set ftp:ssl-allow off;" -u userName,passWord -p 21 74.50.ip.address/orURLhere