Below is a set of scripts that I use to monitor an FTP site, when something is found uploaded it downoads the file, moves the orginal to archive, decrypts the pgp , moves the files to their final resting places, and emails me with a notification.

ccg
./control > ccgtransaction`date ‘+%Y%m%d’`.log
mv ccgtransaction* /mnt/agdevftp/CLIENTS/comprehensive/fromCLIENT/Archive/Log/

control
#mount -t smbfs -o username=will,password=passwdhere //agit/support /mnt/network
#umount /mnt/network

./listfiles
if diff –brief list list.default
then
set new “no”
echo “`date` No new files.” >> log
else
echo “New File” > newfile
echo “`date` New files present.” >> log
while read file
do
if [[ $file == archive* ]]
then
echo “`date` $file was found to be archived”
else
echo “`date` $file” >> log
./ftpget $file
./ftprename $file
fi
done
cd files
./../decryptcntl *
cd ..
./movefiles
fi

if [ -f newfile ]
then
php mail.php
rm -f newfile
fi

decryptcntl
./../decryptpgp $1
./../decryptpgp $2
./../decryptpgp $3
./../decryptpgp $4
./../decryptpgp $5
./../decryptpgp $6
./../decryptpgp $7
./../decryptpgp $8
./../decryptpgp $9
./../decryptpgp $10

decryptpgp
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn’t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}

set timeout -1

set arg1 [lindex $argv 0]
set arg2 [lindex $argv 1]

cd /root/ftp/files

spawn gpg –decrypt-files $arg1
match_max 100000
expect “Enter passphrase: “
send “pgppasshere\r”
send “\r\r”
expect eof

ftpclear
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn’t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}

set timeout -1
spawn ftp ftp.eedi.net
match_max 100000
expect “Name (ftp.eedi.net:root): “
send — “userhere\r”
expect “Password:”
send — “passwdhere\r”
expect “ftp> “
send — “cd inbox\r”
expect “ftp> “
send — “prompt\r”
expect “ftp> “
send — “lcd files\r”
expect “ftp> “
send — “mdelete *\r”
expect “ftp> “
send — “bye\r”
expect eof

ftpget
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn’t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}

set arg1 [lindex $argv 0]

set timeout -1
spawn ftp ftp.eedi.net
match_max 100000
expect “Name (ftp.eedi.net:root): “
send — “userhere\r”
expect “Password:”
send — “passwdhere\r”
expect “ftp> “
send — “cd inbox\r”
expect “ftp> “
send — “prompt\r”
expect “ftp> “
send — “lcd files\r”
expect “ftp> “
send — “mget $arg1\r”
expect “ftp> “
send — “bye\r”
expect eof

ftprename
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn’t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}

set arg1 [lindex $argv 0]
#set arg2 [lindex $argv 1]
set arg2 “archive/$arg1”

set timeout -1
spawn ftp ftp.eedi.net
match_max 100000
expect “Name (ftp.eedi.net:root): “
send — “userhere\r”
expect “Password:”
send — “passwdhere\r”
expect “ftp> “
send — “cd inbox\r”
expect “ftp> “
send — “rename $arg1\r”
expect “(to-name) “
send “$arg2\r”
expect “ftp> “
send — “bye\r”
expect eof

listfiles
#!/usr/bin/expect -f

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn’t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s — $arg
}
}

set timeout -1
spawn ftp ftp.eedi.net
match_max 100000
expect “Name (ftp.eedi.net:root): “
send — “userhere\r”
expect “Password:”
send — “passwdhere\r”
expect “ftp> “
send — “cd inbox\r”
expect “ftp> “
send — “prompt\r”
expect “ftp> “
send — “mls – list\r”
expect “ftp> “
send — “bye\r”
expect eof

mail.php

mail(“will@aghealth123.com,jonn@aghealth123.com”,”CCG Activity”,”CCG Activity has been detected\nAll files should have been transfered and inital processing completed\nPlease verify this has occured and view the applicable log\n\\\\agdev\\ftp\\CLIENTS\\comprehensive\\fromCLIENT\\Archive\\Log”,
“From: CCGActivity\n”);
?>

mapdrives
mount -t smbfs -o username=user,password=passwd //agapp/mars3 /mnt/agappmars3
mount -t smbfs -o username=user,password=passwd //agdev/ftp /mnt/agdevftp

movefile
cd /root/ftp/files
mv *.pgp /mnt/agdevftp/CLIENTS/comprehensive/fromCLIENT/Archive/
mv * /mnt/agappmars3/EDIFILES/CCG/fromClient

Advertisements