#--------------------------------------------------------------------- # demo-ftpconnect.tcl # # Demo tcl for IRC bot eggdrop # # Upon a ".ftpconnect" on the partyline will make an outgoing # FTP connection and hand over control to another procedure. # # v0: 21-Sep-2003 # v1: 19-Oct-2003 # + catch if connect error (DNS lookup failed) #--------------------------------------------------------------------- set ftphost ftp.eggheads.org set ftpport 21 bind dcc n ftpconnect dcc:ftpconnect #--------------------------------------------------------------------- # proc dcc:connect makes and outgoing connection, sends the "HEAD" # request and hands over control to the receive procedure. #--------------------------------------------------------------------- proc dcc:ftpconnect { hand dccidx text } { global ftphost global ftpport # make an outgoing connection # "conidx" will contain the idx of the outgoing connection if { [catch { set conidx [connect $ftphost $ftpport] }\ errmsg ] } { set line "No connection to $ftphost ($errmsg)." putdcc $dccidx $line return 1 } putlog "FTP CON: Connecting to $ftphost:$ftpport ($conidx)." # the FTP server will send a numeric 220 when ready # hand over control to the receive procedure. control $conidx connect:ftprcv # log the command return 1 } #--------------------------------------------------------------------- # Upon a succesfull connection, all text sent by the server is # absorbed by the connect:ftprcv procedure. #--------------------------------------------------------------------- proc connect:ftprcv { idx text } { # if connection closed: control back to eggdrop if { $text == "" } { putlog "FTP RCV: connection closed by server." return 1 } # putlog any text that eggdrop receives putlog "FTP RCV: $text" # test for numeric # if first char is a space, it is not a numeric if { [string index $text 0] == " " } { # putlog "FTP NUM: not a numeric!" # new text should come to this proc return 0 } # scan numeric # either it is a 3-digit numeric followed by a space # or a 3-digit numeric followed by a dash if { [scan $text "%4s" numeric] != 1 } { # line does not start with a word (odd!) # new text should come to this proc return 0 } # reply to numerics send by the FTP server # 220 -> server ready, send USER # 331 -> USER accepted, send PASS # 530 -> anonymous not accepted: terminate connection # 230- -> login info, ignore # 230 -> logged in, request HELP # 214- -> help information, ignore # 214 -> HELP sent by server, send a QUIT # 221 -> server said goodbye # default (all other cases): terminate connection switch -- $numeric { 220 { putlog "FTP NUM: 220"; putdcc $idx "USER anonymous" } 331 { putlog "FTP NUM: 331"; putdcc $idx "PASS test@myhost.com" } 530 { putlog "FTP NUM: 530"; putdcc $idx "QUIT" } 230- { putlog "FTP NUM: 230- (ignoring)"; return 0 } 230 { putlog "FTP NUM: 230"; putdcc $idx "HELP" } 214- { putlog "FTP NUM: 214- (ignoring)"; return 0 } 214 { putlog "FTP NUM: 214"; putdcc $idx "QUIT" } 221 { putlog "FTP NUM: 221"; return 1 } default { putlog "FTP NUM: unknown ($numeric)"; return 1 } } # new text should come to this proc return 0 } putlog "Loaded (version 1): Demo FTP connect."