Tuesday, February 1, 2011

BASH : FTP Synchronization

du -h -> returns the size in Mega of the current files that are in the current folder. You can specify a certain folder
lftp user@192.168.1.10 -> Password is required
Password:password
The following will appear: lftp user@192.169.1.10:~>
lftp user@192.169.1.10:~>ls ->here we can operate commands and create files, folders
mkdit temp2 -> create a remote folder
help mirror -> specified remote directory to local directory
lftp user@192.169.1.10:~>bye ->the connection with the computer is finished


lftp user@192.168.1.10:~> Password is required
Password:password
lftp user@192.168.1.10:~>cd temp2/
cd ok, cwd=/home/user/temp2
lftp user@192.168.1.10:~temp2> mirror -n -> all the local files will be send to the remote host
touch ftpsynchronize.lftp
#!/bin/bash
open -uuser,password 192.168.1.10
cd temp2
lcd /root/temp2 # localy we are in temp2
mirror -Rn
#END


lftp -f ftpsynchronize.lftp -> open the connection


ssh 192.168.1.10 -> enter the password and all the file were transferred from local host to remote host


touch ftpsynchronize.sh -> synchronize folder between computers
pico ftpsynchronize.sh
#!/bin/bash
#Author
#Date
#Purpose
SCRIPTHOME="/root/temp2"
LFTPSCRIPT=$SCRIPTHOME/ftpssyncronize.lftp


lftp -f $LFTPSCRIPT


#END
Result -> the file were copied from local to remote host
rm -rf * - all files are removed


cp ftpsynchronize.sh /etc/cron.hourly/ -> this script will run every hour

1 comment:

  1. Nice post. Your information is really good. Thank you for sharing.........................


    FTP Synchronization

    ReplyDelete