Tuesday, June 7, 2011

SwiFTP and LFTP to do some syncing

Well, I should be studying but instead I'm delving into some FTP stuff and how to do some syncing across particular folders. All this is due me wanting to make my Music listening a hell of a lot easier. At present, Winamp does not have a Linux version and this sucks because there is one feature of Winamp has just come out and is fricken awesome - Wireless Sync, pretty self explanatory.

So I need a work around.

On your Android device
At present, I'm running Gingerbread 2.3.3 on my SGS2. Download and install SwiFTP from the Android market - information here. I've found this app simple and easy to setup - thus far. Once it is fired up, put in the details that you wish to have for your FTP server (your device) - user, pass, port (anything in the 1000's usually works, but not always). Most importantly, where it says:
Stay within folder (e.g. /sdcard):
...just put a...
/
...in the box. Later on when you connect from your client, you can point LFTP to which ever folder you wish - hopefully. Some info about why you should do this here (search for 'root').

Now, I say this because there may be a SU (superuser) or root error (is you device rooted?) in which you will not be given access to the folder on your phone, even if you typed the password in correctly. There needs to be a work around for this because there are rumors that rooting your device can disallow it from using certain Provider apps, e.g. any Optus apps on my device. And frankly, once rooted, I'm not sure if factory defaults can be set.

Once this is done, save the settings and the FTP server will start automatically.

On your Linux box
With your FTP server running, open up terminal on your Linux box and type in the following:
lftp -u name -p 1234 ftp://192.168.x.xx:/
-u specifies the username
-p specifies the port which you setup earlier on the device

You should be prompted to enter a password which was the one you setup earlier. And if all goes well, you will have a line that looks like this:
lftp name@192.168.x.xx:/
And this verifies that you can make the connection. Now, if you type in 'ls', you should be given all the files and folders of that folder. Neat!

Syncing with rsync -> FAIL
Rsync is a program which appears to come pre-installed on Linux. It allows for syncing folders across FTP and on your machine. It seems to be much like creating a symlink but is only run when the user says so. There is a neat little thread here which says it all.

So...I've just finished trying to get rsync to work with my FTP server, but everywhere I go says that it cannot be done :(. Well at least I know about Rsync I guess. There is a solution however...read on.

LFTP and Mirror
So the solution, as posted here by easel (round of applause!), is to use 'mirror' to do the syncing over FTP using LFTP. So you'll want to make a script file with the code that easel has posted. I've changed mine a little for my needs:
lftp -c "set ftp:list-options -a;
open ftp://user:password@your.ftp.com:port; 
lcd ./web;
cd /web/public_html;
mirror --reverse --delete --use-cache --verbose --allow-chown --no-umask --parallel=2"
Some of the options used include:
lcd - is the local directory you want to sync,
cd - is the directory on the FTP server in which you wish to sync
and...
mirror - sync the two folders, choosing the local directory as the master (everything on cd that isn't in lcd will be deleted). Type 'man lftp' for more information on the options used here, --reverse, --delete etc.

Don't forget to change the permissions to user executable, chmod u+x.

Note: lftp uses ftp protocols to transfer data and is therefore, not secure (ssh is an example of a secure transfer protocol, need to investigate how I can use it instead). The password that was entered in earlier could easily be hacked (discovered) by anyone listening to the 'conversation' between your phone and your computer...so be careful!

Pretty neat huh! That's it. It may need to be run from the CLI, or you can create a launcher on the desktop. That should work.

Ciao and happy syncing!

No comments:

Post a Comment