mads3n Posted February 8, 2006 Share Posted February 8, 2006 Hi, i need help. Im almost done with a autoIt3 script that: acceses a internet ftp server, loads a text-file into a text edit area. but now i've run into a problem i have made a combobox that would help by choosing what file i would like to load (i have 5 different files) ¨ heres my code, hope you guys can help (its the part with "$dag" ) expandcollapse popup#include <GuiConstants.au3> $mainwindow = GuiCreate("lmandag V.1.0 full", 400, 400) $oobutton = GUICtrlCreateButton ( "Åben din personlige text!", 50, 5, 140, 60, 0x0300) $Cancel_Btn = GUICtrlCreateButton ( "LUK", 10, 5, 40, 60, 0x0300) $gembutton = GUICtrlCreateButton ( "GEM", 190, 5, 40, 60, 0x0300) $dag = GUICtrlCreateCombo ("lmandag", 235, 5, 80, 90); create first item GUICtrlSetData(-1,"ltirsdag|lonsdag|ltorsdag|lfredag"); add other item snd set a new default $txt = GuiCtrlCreateEdit("TRYK PÅ: Åben din personlige text!", 10, 110, 380, 280) ; Function to empty a text file ; Author(s) : Groumphy ; Alias of FileOpen Mode 2 Func _EraseContentOfTxtFile($iFile) ; failure = -1 ; success = File is empty Return FileOpen($iFile, 2) FileClose($iFile) EndFunc Func _FTPput($s_p_Host, $s_p_PathFile, $s_p_Acc, $s_p_Pwd, $s_p_Cd = '', $i_p_Check = 0, $s_p_Aftp = '') ; Declaring local variables. Local $i_p_Return ; Creating a random nummber to minimize the chance of writing to an existing file. Local $i_p_Random = Random(100000000, 999999999, 1) ; Creating the file. Local $h_p_CmdFile = FileOpen(@TempDir & "\FTPcmds" & $i_p_Random & ".txt", 1) ; Check if wildcards are used. If StringInStr($s_p_PathFile, "*") <> 0 Then Local $i_p_Check = 0 ; Getting the path and the filename from $s_p_PathFile. Local $s_p_Path = StringTrimRight($s_p_PathFile, StringLen($s_p_PathFile) - StringInStr($s_p_PathFile, "\", 0, -1) + 1) Local $s_p_File = StringTrimLeft($s_p_PathFile, StringInStr($s_p_PathFile, "\", 0, -1)) ; Create an FTP command file if the file is sucsesfully created. If $h_p_CmdFile <> -1 Then ; Writing the account and password. FileWriteLine($h_p_CmdFile, $s_p_Acc & @CRLF) FileWriteLine($h_p_CmdFile, $s_p_Pwd & @CRLF) ; Set the transfermode to binary FileWriteLine($h_p_CmdFile, "binary" & @CRLF) ; Additional FTP commands passed to the function are actioned here. If $s_p_Aftp <> '' Then FileWriteLine($h_p_CmdFile, $s_p_Aftp & @CRLF) ; Making the destination dir if it doesnot exist FileWriteLine($h_p_CmdFile, 'mkdir ' & $s_p_Cd & @CRLF) ; Set the destination dir if one is given. Else 'root' will be used. If $s_p_Cd <> '' Then FileWriteLine($h_p_CmdFile, "cd " & $s_p_Cd & @CRLF) ; Set the local directory and send the files. FileWriteLine($h_p_CmdFile, "lcd " & $s_p_Path & @CRLF) FileWriteLine($h_p_CmdFile, "mput " & $s_p_File & @CRLF) ; If $i_p_Check is set to 1 it will get the transferred file back to a check area so we can confirm it worked. If $i_p_Check = 1 Then FileWriteLine($h_p_CmdFile, "lcd " & @TempDir & @CRLF) FileWriteLine($h_p_CmdFile, "mget " & $s_p_File & @CRLF) EndIf ; Closes the FTP connecetion and exits the FTP program. FileWriteLine($h_p_CmdFile, "close" & @CRLF) FileWriteLine($h_p_CmdFile, "quit" & @CRLF) ; Closes the file. FileClose($h_p_CmdFile) EndIf ; Start FTP with the cmdfile to transfer the file(s) concerned. RunWait(@ComSpec & " /c " & 'ftp -v -i -s:' & @TempDir & "\FTPcmds" & $i_p_Random & ".txt " & $s_p_Host, "", @SW_HIDE) ; Setting the return value's. If $i_p_Check = 1 And Not FileExists(@TempDir & "\" & $s_p_File) Then $i_p_Return = -1 ElseIf $i_p_Check = 1 And FileExists(@TempDir & "\" & $s_p_File) Then $i_p_Return = 1 Else $i_p_Return = 0 EndIf ; Delete the temp files. FileDelete(@TempDir & "\" & $s_p_File) FileDelete(@TempDir & "\FTPcmds" & $i_p_Random & ".txt") ; Return the returnvalue. Return $i_p_Return EndFunc ;==>_FTPput ; PROGRESS GuiCtrlCreateLabel("Fremgang:", 10, 82) $progress = GuiCtrlCreateProgress(70, 80, 320, 20, 0x01) GuiCtrlSetData(-1, 00) ;Show window/Make the window visible GUISetState(@SW_SHOW) While 1 ;After every loop check if the user clicked something in the GUI window $msg = GUIGetMsg() Select ;Check if user clicked on the close button Case $msg = $GUI_EVENT_CLOSE ;Exit the script Exit ;Check if user clicked on the "OK" button Case $msg = $oobutton InetGet("http://www.skjernhs.1go.dk/lektier/", "$dag" & ".txt", 1, 0) sleep(2000) $open = FileOpen("$dag" & ".txt", 0) $File_Read = FileRead("$dag" & ".txt", FileGetSize("$dag" & ".txt")) GUICtrlDelete($txt) ; EDIT $txt = GuiCtrlCreateEdit($File_Read, 10, 110, 380, 280) _EraseContentOfTxtFile("$dag" & ".txt") ;Check if user clicked on the "OK" button Case $msg = $gembutton $new = ControlGetText("lmandag", "", "Edit1") FileWrite("lmandag.txt", $new) GUICtrlDelete($progress) $progress = GuiCtrlCreateProgress(70, 80, 320, 20, 0x01) GuiCtrlSetData(-1, 50) sleep(500) _FTPput('195.245.210.174', 'lmandag.txt', 'ftp-skjernhs-1go', '*********') MsgBox(64, "INFO", "Filen er nu opdateret") GuiCtrlSetData(-1, 100) sleep(1000) GuiCtrlSetData(-1, 00) ;Check if user clicked on the "CANCEL" button Case $msg = $Cancel_Btn Exit EndSelect WEnd heres the file to download lektier.au3 Mads3n.dk Link to comment Share on other sites More sharing options...
Nuffilein805 Posted February 8, 2006 Share Posted February 8, 2006 (edited) your problem is the "$dag" in your select-statement there shouldn't be any " without those your script should work have fun scripting Edited February 8, 2006 by Nuffilein805 my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
mads3n Posted February 8, 2006 Author Share Posted February 8, 2006 (edited) your problem is the "$dag" in your select-statement there shouldn't be any " without those your script should work have fun scripting Thanks for the help, but now it creates a file named 6.txt, and loads this into the text area: <html><head><title>Index of /lektier/</title></head><body bgcolor=#ffffff><h2>Index of /lektier/</h2><pre>v <a href="?sortby=1">Name</a> <a href="?sortby=6">Last Modified</a> <a href="?sortby=2">Size</a> _____________________________________________________________ <a href="/">Parent directory</a> <a href="lektier.png">lektier.png</a> 7 Feb 06 23:25 19.0Kb <a href="lfredag.bak">lfredag.bak</a> 7 Feb 06 23:25 0.7Kb <a href="lfredag.htm">lfredag.htm</a> 7 Feb 06 23:25 0.7Kb <a href="lfredag.txt">lfredag.txt</a> 7 Feb 06 23:25 0.0Kb <a href="lmandag.bak">lmandag.bak</a> 7 Feb 06 23:25 0.7Kb <a href="lmandag.htm">lmandag.htm</a> 7 Feb 06 23:25 0.7Kb <a href="lmandag.txt">lmandag.txt</a> 7 Feb 06 23:25 0.0Kb <a href="lonsdag.bak">lonsdag.bak</a> 7 Feb 06 23:25 0.7Kb <a href="lonsdag.htm">lonsdag.htm</a> 7 Feb 06 23:25 0.7Kb <a href="lonsdag.txt">lonsdag.txt</a> 7 Feb 06 23:25 0.0Kb <a href="ltirsdag.bak">ltirsdag.bak</a> 7 Feb 06 23:25 0.7Kb <a href="ltirsdag.htm">ltirsdag.htm</a> 7 Feb 06 23:25 0.7Kb <a href="ltirsdag.txt">ltirsdag.txt</a> 7 Feb 06 23:25 0.0Kb <a href="ltorsdag.bak">ltorsdag.bak</a> 7 Feb 06 23:25 0.7Kb <a href="ltorsdag.htm">ltorsdag.htm</a> 7 Feb 06 23:25 0.7Kb <a href="ltorsdag.txt">ltorsdag.txt</a> 7 Feb 06 23:25 0.0Kb _____________________________________________________________</pre></body></html> update..the code (editted is): expandcollapse popup#include <GuiConstants.au3> $mainwindow = GuiCreate("lmandag V.1.0 full", 400, 400) $oobutton = GUICtrlCreateButton ( "Åben din personlige text!", 50, 5, 140, 60, 0x0300) $Cancel_Btn = GUICtrlCreateButton ( "LUK", 10, 5, 40, 60, 0x0300) $gembutton = GUICtrlCreateButton ( "GEM", 190, 5, 40, 60, 0x0300) $dag = GUICtrlCreateCombo ("lmandag", 235, 5, 80, 90); create first item GUICtrlSetData(-1,"ltirsdag|lonsdag|ltorsdag|lfredag"); add other item snd set a new default $txt = GuiCtrlCreateEdit("TRYK PÅ: Åben din personlige text!", 10, 110, 380, 280) ; Function to empty a text file ; Author(s) : Groumphy ; Alias of FileOpen Mode 2 Func _EraseContentOfTxtFile($iFile) ; failure = -1 ; success = File is empty Return FileOpen($iFile, 2) FileClose($iFile) EndFunc Func _FTPput($s_p_Host, $s_p_PathFile, $s_p_Acc, $s_p_Pwd, $s_p_Cd = '', $i_p_Check = 0, $s_p_Aftp = '') ; Declaring local variables. Local $i_p_Return ; Creating a random nummber to minimize the chance of writing to an existing file. Local $i_p_Random = Random(100000000, 999999999, 1) ; Creating the file. Local $h_p_CmdFile = FileOpen(@TempDir & "\FTPcmds" & $i_p_Random & ".txt", 1) ; Check if wildcards are used. If StringInStr($s_p_PathFile, "*") <> 0 Then Local $i_p_Check = 0 ; Getting the path and the filename from $s_p_PathFile. Local $s_p_Path = StringTrimRight($s_p_PathFile, StringLen($s_p_PathFile) - StringInStr($s_p_PathFile, "\", 0, -1) + 1) Local $s_p_File = StringTrimLeft($s_p_PathFile, StringInStr($s_p_PathFile, "\", 0, -1)) ; Create an FTP command file if the file is sucsesfully created. If $h_p_CmdFile <> -1 Then ; Writing the account and password. FileWriteLine($h_p_CmdFile, $s_p_Acc & @CRLF) FileWriteLine($h_p_CmdFile, $s_p_Pwd & @CRLF) ; Set the transfermode to binary FileWriteLine($h_p_CmdFile, "binary" & @CRLF) ; Additional FTP commands passed to the function are actioned here. If $s_p_Aftp <> '' Then FileWriteLine($h_p_CmdFile, $s_p_Aftp & @CRLF) ; Making the destination dir if it doesnot exist FileWriteLine($h_p_CmdFile, 'mkdir ' & $s_p_Cd & @CRLF) ; Set the destination dir if one is given. Else 'root' will be used. If $s_p_Cd <> '' Then FileWriteLine($h_p_CmdFile, "cd " & $s_p_Cd & @CRLF) ; Set the local directory and send the files. FileWriteLine($h_p_CmdFile, "lcd " & $s_p_Path & @CRLF) FileWriteLine($h_p_CmdFile, "mput " & $s_p_File & @CRLF) ; If $i_p_Check is set to 1 it will get the transferred file back to a check area so we can confirm it worked. If $i_p_Check = 1 Then FileWriteLine($h_p_CmdFile, "lcd " & @TempDir & @CRLF) FileWriteLine($h_p_CmdFile, "mget " & $s_p_File & @CRLF) EndIf ; Closes the FTP connecetion and exits the FTP program. FileWriteLine($h_p_CmdFile, "close" & @CRLF) FileWriteLine($h_p_CmdFile, "quit" & @CRLF) ; Closes the file. FileClose($h_p_CmdFile) EndIf ; Start FTP with the cmdfile to transfer the file(s) concerned. RunWait(@ComSpec & " /c " & 'ftp -v -i -s:' & @TempDir & "\FTPcmds" & $i_p_Random & ".txt " & $s_p_Host, "", @SW_HIDE) ; Setting the return value's. If $i_p_Check = 1 And Not FileExists(@TempDir & "\" & $s_p_File) Then $i_p_Return = -1 ElseIf $i_p_Check = 1 And FileExists(@TempDir & "\" & $s_p_File) Then $i_p_Return = 1 Else $i_p_Return = 0 EndIf ; Delete the temp files. FileDelete(@TempDir & "\" & $s_p_File) FileDelete(@TempDir & "\FTPcmds" & $i_p_Random & ".txt") ; Return the returnvalue. Return $i_p_Return EndFunc ;==>_FTPput ; PROGRESS GuiCtrlCreateLabel("Fremgang:", 10, 82) $progress = GuiCtrlCreateProgress(70, 80, 320, 20, 0x01) GuiCtrlSetData(-1, 00) ;Show window/Make the window visible GUISetState(@SW_SHOW) While 1 ;After every loop check if the user clicked something in the GUI window $msg = GUIGetMsg() Select ;Check if user clicked on the close button Case $msg = $GUI_EVENT_CLOSE ;Exit the script Exit ;Check if user clicked on the "OK" button Case $msg = $oobutton InetGet("http://www.skjernhs.1go.dk/lektier", $dag & ".txt", 1, 0) sleep(2000) $open = FileOpen($dag & ".txt", 0) $File_Read = FileRead($dag & ".txt", FileGetSize($dag & ".txt")) GUICtrlDelete($txt) ; EDIT $txt = GuiCtrlCreateEdit($File_Read, 10, 110, 380, 280) _EraseContentOfTxtFile($dag & ".txt") ;Check if user clicked on the "OK" button Case $msg = $gembutton $new = ControlGetText($dag & ".txt", "", "Edit1") FileWrite( $dag & ".txt", $new) GUICtrlDelete($progress) $progress = GuiCtrlCreateProgress(70, 80, 320, 20, 0x01) GuiCtrlSetData(-1, 50) sleep(500) _FTPput('195.245.210.174', $dag ".txt", 'ftp-skjernhs-1go', '***') MsgBox(64, "INFO", "Filen er nu opdateret") GuiCtrlSetData(-1, 100) sleep(1000) GuiCtrlSetData(-1, 00) ;Check if user clicked on the "CANCEL" button Case $msg = $Cancel_Btn Exit EndSelect WEnd Edited November 11, 2006 by mads3n Mads3n.dk 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