Voici un exemple d’utilisation basique : transfert des fichiers contenus dans un répertoire et déplacement de ceux-ci dans un sous-dossier.
Méthode 1 : LFTP
#!/bin/sh
HOST="ftp.domain.tld"
USER="ftpuser"
PASS="PassWord"
REP_BASE="/home/user/ftpbackup/"
REP_ARCHIVE="${REP_BASE}archived/"
/usr/bin/lftp ftp://${USER}:${PASS}@${HOST} -e "mput ${REP_BASE}* ; quit";
EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
echo "Error";
else
echo "Transfert complete. Move the files";
find ${REP_BASE} -maxdepth 1 -type f -exec mv -v {} {REP_ARCHIVE} \;
fi
exit 0;Méthode 2, l’alternative "FTP standard"
#!/bin/sh
HOST="ftp.domain.tld"
USER="ftpuser"
PASS="PassWord"
REP_BASE="/home/user/ftpbackup/"
REP_ARCHIVE="${REP_BASE}archived/"
/usr/bin/ftp -v -n -i ${HOST} <<EOF
user ${USER} ${PASS}
cd /
lcd ${REP_BASE}
binary
mput ./*
quit
EOF
EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
echo "Error";
else
echo "Transfert complete. Move the files";
find ${REP_BASE} -maxdepth 1 -type f -exec mv -v {} {REP_ARCHIVE} \;
fi
exit 0;
Tags
Infos