package require FTP 0.8

bind pub -|- !testftp testftp


proc testftp {nick uhost hand chan arg} {
set arg [split $arg]
   set ftphost [lindex $arg 0]
   set ftpport [lindex $arg 1]
   set ftpuser [lindex $arg 2]
   set ftppass [lindex $arg 3]
   putserv "PRIVMSG $chan :checking ftp: [b]ftp://$ftpuser:$ftppass@$ftphost:$ftpport[b]"
   if {[FTP::Open $ftphost $ftpport $ftpuser $ftppass]} {
	putserv "PRIVMSG $chan :Connection Successful! (FTP Alive)"
	set folder_list [FTP::List]
	set listing [list $folder_list]
	set f [open $ftphost.list.txt w]
        foreach list $listing {
        puts $f "$list"
	puts $f ""
        }
	close $f

	set f [open alive.txt w]
        puts $f "$ftphost $ftpport $ftpuser $ftppass"
        puts $f ""
        close $f

	} {
        putserv "PRIVMSG $chan :Connection refused! (Invalid Password Or User)"
	set f [open dead.txt w]
        puts $f "$ftphost $ftpport $ftpuser $ftppass"
        puts $f ""
        close $f

	}
	FTP::Close
}