arcker Posted April 2, 2006 Share Posted April 2, 2006 (edited) edit : in the title "binary and/or ascii files" i finally managed to create an ftp client in auto it !! yes , i did... long time of work, but i will post the current script here so, to begin, i've managed to list all the file of the directory, but now i need to retrieve them, with the retr command so i need to convert what i receive with tcprecv to a file...oula but i don't know how to do it i've searched on the forum, but i'm lost, maybe i could use larry fonctions but... i really don't know how to do it i will make some UDF's with what i've learned (_ftpfilegetsize real now, and without dllcall) here it is i hope you can learn a lot of ftp protocol, because on internet, documentations are not really clear about data transfers... here is the script i must thanx a lot Adam 123, because i've used his source code to adapt it for ftp, and his GUI expandcollapse popup;original script - IRC client in Autoit v3 beta by Michael Mcstay AKA ( ^sleepy^s-sin scripting) http://sleepys-sin.freeserverhost.net/sleepys__sin.htm #include <GuiConstants.au3> #include <String.au3> #include <GuiCombo.au3> #include <file.au3> #Include <Constants.au3> #include <Misc.au3> opt("SendKeyDelay", 1) ; ----------------- settings --------------- Global $flash = "yes" Global $ftimes = 2 Global $fdelay = 0.9 Dim $socket2 Global $failsafe #Include <GuiEdit.au3>; not to be included if compiling If @Compiled = 1 Then $failsafe = "yes" Else $failsafe = "no" EndIf $dpass = "Your password will be encryped"; default text for password $passad = "PWD:" $pass2 = "encrypt" $level = 2 ; --------------------- config ------------------- opt("TrayAutoPause", 0) ;0=no pause, 1=Pause ;Opt("TrayMenuMode",0) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not retur TraySetToolTip("IRC") TraySetIcon("C:\Documents and Settings\Adam\My Documents\Autoit\irc.ico") TrayItemSetText($TRAY_ITEM_PAUSE, "Pause Program") $valitem = TrayCreateItem("Val:") TrayCreateItem("") $aboutitem = TrayCreateItem("About") opt("TrayOnEventMode", 1) ;0=disable, 1=enable Global $lastkey="" ;$exit = TrayCreateItem("Exit") ;TrayItemSetOnEvent(-1,"onexit") TraySetPauseIcon("shell32.dll", 12) $fdelay = $fdelay * 1000 $path = @ProgramFilesDir & "\Adam1213\IRC" DirCreate($path) FileChangeDir($path) FileInstall("C:\Documents and Settings\Adam\My Documents\Autoit\help.html", $path & "\help.html", 1) $settingsplace = $path & "\settings.ini" Global $overide = "no" Global $lastplacechanged = "no" Global $scroll = "yes" Global $raw = "no" Global $msgboxm = "on" Global $traym = "on" $passadl = StringLen($passad) + 1 Global $connected = "no", $exit = "no", $fping = "0", $text = "" opt("GUIOnEventMode", 1) Dim $sendtextb, $socket, $recv, $err, $g_IP $regplace = "HKEY_LOCAL_MACHINE\SOFTWARE\Adam1213 Software\IRC" $regplace2 = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit" ; ------------- Nick --------------------- Global $nick = RegRead($regplace, "1 Nick") If "t" & $nick = "t" Then $nick = @UserName & Random(1, 99, 1) RegWrite($regplace, "1 Nick", "REG_SZ", $nick) EndIf $newnick = $nick ; ------------- Name --------------------- Global $name = Regread($regplace, "2 Name") If "t" & $name = "t" Then $name = "Anonymous" RegWrite($regplace, "2 Name", "REG_SZ", $name) EndIf ; ------------- Room --------------------- Global $chatto = Regread($regplace, "3 Room") If "t" & $chatto = "t" Then $chatto = "#adam1213" RegWrite($regplace, "3 Room", "REG_SZ", $chatto) EndIf $joinf = $chatto ; ------------- server --------------------- Global $server = Regread($regplace, "4 Server") If "t" & $server = "t" Then $server = "ftp.fr.debian.org" RegWrite($regplace, "4 Server", "REG_SZ", $server) EndIf ; ------------- Port --------------------- Global $port = Regread($regplace, "5 Port") If "t" & $port = "t" Then $port = "21" RegWrite($regplace, "5 Port", "REG_SZ", $port) EndIf ; ------------- Password --------------------- Global $epassword = Regread($regplace, "6 Password") If "t" & $epassword = "t" Then $epassword = $dpass RegWrite($regplace, "6 Password", "REG_SZ", $epassword) EndIf ; ---------------- ini settings ------------------------- Global $bcolour = iniread($settingsplace, "Display \ chat log", "Background Colour", "0xFFFFFF"); white is the default Global $tcolour = iniread($settingsplace, "Display \ chat log", "Text Colour", "0xFF0000"); black is the default Global $fsize = iniread($settingsplace, "Display \ chat log", "Text Size", "9") Global $fweight = iniread($settingsplace, "Display \ chat log", "Text Weight", "400") Global $fattribute = iniread($settingsplace, "Display \ chat log", "Text Attribute", " ") Global $fontname = iniread($settingsplace, "Display \ chat log", "Text Font", " ") If StringInStr($epassword, $passad) < 1 And $epassword <> $dpass Then $epassword = $passad & _StringEncrypt(1, $epassword, $pass2, $level); encrypt RegWrite($regplace, "6 Password", "REG_SZ", $epassword) EndIf $password = _StringEncrypt(0, StringMid($epassword, $passadl), $pass2, $level) ; ------------- connect at start --------------------- $catdelay = Regread($regplace, "6 Connection Delay") If "t" & $catdelay = "t" Then $catdelay = 0 RegWrite($regplace, "6 Connection Delay", "REG_SZ", $catdelay) EndIf Global $connectatstart = "no" If $catdelay > 0 Then $connectatstart = "yes"; if it is 0 than it will be off Global $text = "", $dtext = "", $textd = "", $sendtext = "yes", $showtext = "yes", $monly = "yes" ; --------------- Main program -------------------------------------------- HotKeySet("{Enter}", "EnterSends");register hotkey when our GUI messenger window is active HotKeySet("{f1}", "onhelp");register hotkey Global $title = "Adam1213's IRC Client" ; ------------------------- GUI --------------------------------- $ICGUI = GUICreate($title, 630, 435, (@DesktopWidth - 548) / 2, (@DesktopHeight - 410) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE) GUISetIcon("C:\Documents and Settings\Adam\My Documents\Autoit\irc.ico") ;@SystemDir & "\mspaint.exe" $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("E&xit", $filemenu) GUICtrlSetOnEvent($exititem, "onexit") $mmsettings = GUICtrlCreateMenu("&Settings") $mmsetdisplay = GUICtrlCreateMenu("&Display", $mmsettings) $mmsetchatlog = GUICtrlCreateMenu("&Chat Log", $mmsetdisplay) $mmsetclfont = GUICtrlCreateMenuItem("&Font", $mmsetchatlog) $mmsetcltext = GUICtrlCreateMenuItem("&Text colour", $mmsetchatlog) $mmsetclbgc = GUICtrlCreateMenuItem("&Background colour", $mmsetchatlog) GUICtrlSetOnEvent($mmsetclfont, "onfont") GUICtrlSetOnEvent($mmsetcltext, "ontextcolourchange") GUICtrlSetOnEvent($mmsetclbgc, "onbackcolourchange") $helpmenu = GUICtrlCreateMenu("&help") $helpitem = GUICtrlCreateMenuItem("&Help", $helpmenu) $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu) $updateitem = GUICtrlCreateMenuItem("&Update", $helpmenu) GUICtrlSetOnEvent($helpitem, "onhelp") $Label_2 = GUICtrlCreateLabel("Server", 10, 10, 40, 20); Display server $vserver = GUICtrlCreateCombo($server, 60, 10, 140, 30); Input server GUICtrlSetData(-1, "ftp.fr.debian.org|irc.freenode.net", $server) $vPort = GUICtrlCreateLabel("Port", 210, 10, 30, 20) ; Display Port $vPorte = GUICtrlCreateInput($port, 260, 10, 40, 20) ; Input port $dpassword = GUICtrlCreateButton("Password", 330, 10, 60, 20); Button connect $vName = GUICtrlCreateLabel("Name", 10, 40, 40, 20) ; Display Name $vnamei = GUICtrlCreateInput($name, 60, 40, 120, 20) ; Input Name $vnick1 = GUICtrlCreateLabel("Nick", 210, 40, 30, 20) ; Display nick $vnick1e = GUICtrlCreateInput($nick, 260, 40, 120, 20) ; Input nick $connect = GUICtrlCreateButton("Connect", 410, 30, 100, 20); Button connect $Edit_10 = GUICtrlCreateEdit("", 10, 70, 600, 250, $ES_AUTOVSCROLL + $GUI_SS_DEFAULT_EDIT + $ES_READONLY) ; Edit chat $Label = GUICtrlCreateEdit("", 10, 340, 600, 40) GUICtrlSetBkColor($Edit_10, $bcolour) GUICtrlSetColor($Edit_10, $tcolour) GUICtrlSetFont($Edit_10, $fsize, $fweight, $fattribute, $fontname) ;0x00000200 + $UDS_WRAP $chat12 = GUICtrlCreateInput("", 5, 390, 450, 20) ; Input send $sendtextb = GUICtrlCreateButton("Send", 460, 390, 50, 20) ; Button send GUICtrlSetOnEvent($sendtextb, "onsend") GUICtrlSetOnEvent($connect, "onconnect") GUICtrlSetOnEvent($dpassword, "onpassword") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() _GUICtrlComboSetExtendedUI ($vserver, 1) GUICtrlSetState($connect, $GUI_FOCUS) $begin = TimerInit() While $exit = "no" Sleep(10) If $connected = "no" Then If $connectatstart = "yes" Then If TimerDiff($begin) / 1000 > $catdelay Then Call("onconnect") EndIf EndIf ;--------------the socket Recv ------------------------------ $recv = TCPRecv($socket, 512) ;$recv = $recv & @CRLF & TCPRecv($socket2, 512) If StringInStr($recv,"227")>0 Then ;MsgBox(0,"",$recv) _layerconnection($recv) EndIf ;------------------call socket recv func------------------------- If $recv <> "" Then recv($Edit_10) ;--------------end socket Recv f---------------------------------- WEnd Call("Onsaveinfo") ; ============= FUNCTIONS ======================== ;---------------------- Connect ------------------------------ Func onconnect() if $connected="yes" then TCPCloseSocket( $socket ) TCPShutDown() sleep (20) endif $connected = "yes" ;$begin = TimerInit() GUICtrlSetData($Edit_10, guictrlread($Edit_10) & @CRLF & "---CONNECTING---" & @CRLF) $g_IP = $g_IP TCPStartup() GUICtrlSetState(-1, $GUI_FOCUS) ;----name to number isp---au3 can only use number isp--------------------- $g_IP = TCPNameToIP(guictrlread($vserver)) $socket = TCPConnect($g_IP, guictrlread($vPorte)) If $socket = 1 Then Exit ;--------winsettitle sends connect to the gui title-when connected------------------------------ $title = "establishing connection - Adam1213's IRC Client" WinSetTitle($ICGUI, "", $title) ;------------tcp send the user and nick commands on conenct---------------- $nick = guictrlread($vnick1e) TCPSend($socket, "USER " & $nick & @LF) ;------------------call socket recv func------------------------- $name = guictrlread($vnamei) TCPSend($socket, "PASS " & $name & @LF) Sleep(100) If $failsafe = "no" Then $now = 0 While $now < "2" And $exit = "no"; 120 $now = $now + 1 Sleep(10) ; if _GUICtrlEditGetLineCount($edit_10)>35 then $now=120 WEnd Else Sleep(700) EndIf $title = "Connected - Crash's FTP Client" WinSetTitle($ICGUI, "", $title) $waitfping = "no" ;If StringInStr($server, "bigpond") > 0 Then $waitfping = "yes" #cs If $waitfping = "no" Then Call("onfping") $fping = 2 EndIf #ce GUICtrlSetState($sendtextb, $GUI_FOCUS) ;TCPSend($socket, "PASV" & @LF) ;$dif = TimerDiff($begin) ;$dif=$dif/1000 ;TrayTip ("Connected", "Connect to irc in " & $dif & " secs", 3) EndFunc ;==>onconnect ;--------------On recieve-------------------------------- Func recv($Edit_10) ;@CRLF GUICtrlSetData($Edit_10, guictrlread($Edit_10) & $recv) GUICtrlSetData($Label,$recv) If $scroll = "yes" Then Call("onscroll") If $flash = "yes" Then WinFlash('& $title &', "", $ftimes, $fdelay) EndFunc ;==>recv ; ------------------ On send ----------------------------------------------- Func onsend() $text = "" $textd = "" $sendtext = "yes" $showtext = "yes" $monly = "yes" $text = guictrlread($chat12) If StringInStr($text, "/") = "1" Then Call("oncommands") #cs If $monly = "yes" Then $dtext = $newnick & ": " & $text $text = "privmsg " & $chatto & " :" & $text EndIf #ce If $sendtext = "yes" Then TCPSend($socket, $text & @LF) If $showtext = "yes" Then GUICtrlSetData($Edit_10, guictrlread($Edit_10) & " " & $dtext) $clear = "yes" If $clear = "yes" Then GUICtrlSetData($chat12, '') If $scroll = "yes" Then _GUICtrlEditLineScroll ($Edit_10, 0, 1000) EndFunc ;==>onsend Func OnExit() Call("Onsaveinfo") $exit = "yes" Exit EndFunc ;==>OnExit ; -------------- on first ping ---------------------- Func onfping() $fping = $fping + 1 Sleep(100) TCPSend($socket, @LF & "nick " & $nick & @LF) Sleep(2) TCPSend($socket, @LF & "privmsg nickserv :identify " & $password & @LF) TCPSend($socket, "join " & $joinf & @LF) Sleep(2) EndFunc ;==>onfping ; ----------- on enter --------------------- Func EnterSends() If WinActive($ICGUI) Then ; ------------- If active --------- If $connected = "no" Then Call("onconnect") Return Else ControlFocus($ICGUI, "", $chat12) If StringStripWS(guictrlread($chat12), 3) = "" Then Return Call("onsend") EndIf ; ------------- If not active --------- Else HotKeySet("{Enter}");un-register hotkey Send("{enter}") HotKeySet("{Enter}", "EnterSends");register hotkey EndIf EndFunc ;==>EnterSends ; ----------------------- help ---------------- Func onhelp() If WinActive($ICGUI) Then $lastkey = Regread($regplace2, "LastKey") ; place | key to use type | value RegWrite($regplace2, "LastKey", "REG_SZ", "My Computer\" & $regplace) Global $lastplacechanged = "yes" Run("explorer help.html") Else HotKeySet("{f1}");un-register hotkey Send("{f1}") HotKeySet("{f1}", "onhelp");register hotkey EndIf EndFunc ;==>onhelp ; ------------- change password ----------- Func onpassword() $connectatstart = "no" $tpass = InputBox("Password", "Password", "", "*", 300, 100) If @error = 1 Then Return; 1 = The Cancel button was pushed. If $tpass = "" Then Return $password = $tpass $epassword = $passad & _StringEncrypt(1, $password, $pass2, $level) RegWrite($regplace, "6 Password", "REG_SZ", $epassword) EndFunc ;==>onpassword Func oncommands() ;/me ;/whois ;/part EndFunc ;==>oncommands ; ----------- scroll --------- Func onscroll() If $failsafe = "no" Then _GUICtrlEditLineScroll ($Edit_10, 0, 1000); scroll down Else ControlSend($title, "", $Edit_10, "^{end} {home}") EndIf EndFunc ;==>onscroll ;----------------- chat log Change background colour--------- Func onbackcolourchange() $bcolour = _ChooseColor (2, $bcolour, 2) ;If (@error) Then GUICtrlSetBkColor($Edit_10, $bcolour) ;endif EndFunc ;==>onbackcolourchange ;----------------- chat log change text colour--------- Func ontextcolourchange() $tcolour = _ChooseColor (2, $tcolour, 2) ;If (@error) Then GUICtrlSetColor($Edit_10, $tcolour) ;endif EndFunc ;==>ontextcolourchange ;-------------- Change chat log font -------------------- Func onfont() $fontinfo = _ChooseFont ($fontname, $fsize, 1) ;If (@error) Then $fattribute = $fontinfo[1] $fontname = $fontinfo[2] $fsize = $fontinfo[3] $fweight = $fontinfo[4] ;$fcolour = $fontinfo[5] GUICtrlSetFont($Edit_10, $fsize, $fweight, $fattribute, $fontname) ;endif EndFunc ;==>onfont ; ------------- Save info --------------------- Func Onsaveinfo() FileWrite("log-" & @MDAY & @MON & ".txt", guictrlread($Edit_10)) If $lastplacechanged = "yes" Then RegWrite($regplace2, "LastKey", "REG_SZ", $lastkey) Global $save = Regread($regplace, "7 Save on exit") If "t" & $save = "t" Then $save = "yes" RegWrite($regplace, "7 Save on exit", "REG_SZ", $save) EndIf If $save = "no" Then Return If $save > "-1" And $save < "1000" And $save <> "yes" Then $save1 = MsgBox(4, "Save", "Save settings?", $save); returns | 6 - yes | 7 - no |-1 timed out If $save1 > 6 Then Return EndIf $nick = guictrlread($vnick1e) $name = guictrlread($vnamei) $server = guictrlread($vserver) $port = guictrlread($vPorte) RegWrite($regplace, "1 Nick", "REG_SZ", $nick) RegWrite($regplace, "2 Name", "REG_SZ", $name) RegWrite($regplace, "4 Server", "REG_SZ", $server) RegWrite($regplace, "5 Port", "REG_SZ", $port) ; ---------------- ini settings ------------------------- IniWrite($settingsplace, "Display \ chat log", "Chat Background Colour", $bcolour) IniWrite($settingsplace, "Display \ chat log", "Chat Text Colour", $tcolour) IniWrite($settingsplace, "Display \ chat log", "Text Size", $fsize) IniWrite($settingsplace, "Display \ chat log", "Text Weight", $fweight) IniWrite($settingsplace, "Display \ chat log", "Text Attribute", $fattribute) IniWrite($settingsplace, "Display \ chat log", "Text Font", $fontname) EndFunc ;==>Onsaveinfo Func _layerconnection($tmp) $tmp=_StringBetween1($recv,"(",")") ;MsgBox(0,"",$tmp) $tmp=StringSplit($tmp,",") $port=$tmp[5]*256+$tmp[6] $ip=$tmp[1] & "." & $tmp[2]& "." &$tmp[3]& "."&$tmp[4] ;MsgBox(0,"ok",$ip & ":" & $port) recv($edit_10) $socket2=TCPConnect($ip,$port) ;$read=TCPRecv($read,512) ;$RunPID2 = Run(@ComSpec & " /c " & $SSL_Exe_loc & " s_client -connect localhost:" & $port, "", @SW_SHOW, $STDOUT_CHILD + $STDIN_CHILD) ;$recv = Stdoutrecv($RunPID2);flush buffer ;_TraceRun("<RECV> " & $recv ) Sleep(50) $recv2=1 While StringInStr($recv2,"226")=0 $recv2=TCPRecv($socket2,512) $tableau=StringSplit($recv2,@LF) GUICtrlSetData($Edit_10, guictrlread($Edit_10) & $recv2) WEnd ;MsgBox(0,"",$tableau[3]) GUICtrlSetData($Label,$recv2) If $scroll = "yes" Then Call("onscroll") If $flash = "yes" Then WinFlash('& $title &', "", $ftimes, $fdelay) EndFunc Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0) $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start) Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start) EndFunc to "dir" the directory, type "pasv" and send -> loop problem here, don't care type "list" and here is the list !! look, there is the size and other thx for any help c u arcker Edited April 2, 2006 by arcker -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
arcker Posted April 3, 2006 Author Share Posted April 3, 2006 ok snif so i think i will post my udf from my client dead project i will use the udf's from wouter, but impossible to get the transfer rate -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now