Ganesh2VL Posted March 29, 2017 Posted March 29, 2017 Dears, I have a task to upload file on a website. I have succeed in clicking the upload button to open the file choose(window to choose the file) but after that i couldn't take control/access the file chooser window. WInWait("Choose File to Upload") also tried using WinActivate("Choose File to Upload") ControlFocus("Choose File to Upload","","Edit1") ControlSend("Choose File to Upload","","Edit1","D://File/sample.xml") Dont know what/where is the issue? Can someone suggest/guide me or pls post here a sample code for the file upload task. Thanks VL.Ganesh
JohnOne Posted March 29, 2017 Posted March 29, 2017 I think that box blocks the flow/script. Some spawn another script/process to interact with the window, and others find a winhttp way of uploading a file. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Ganesh2VL Posted March 30, 2017 Author Posted March 30, 2017 Thanks John, As u said the box blocks the flow/script. No other scripts are working unless i manually close the file chooser window.
trancexx Posted March 30, 2017 Posted March 30, 2017 There are other more sensible ways to upload file. You'd need to provide more info. ♡♡♡ . eMyvnE
Ganesh2VL Posted April 2, 2017 Author Posted April 2, 2017 (edited) @Trancexx, my requirement is simple and straight forward but don't know exactly what to do(Just started learning AUTOIT). I want to upload a .txt file to a https web application. Wanna automate the daily task of login to a website and upload a file from local folder. Steps: 1. Open IE with URL, Login web application 2. Redirect to particular page 3. Click browse button to open the "file chooser window" and then select the input file from the given path. 4. Click upload button and wait until the process complete 5. Close the IE. Edited April 2, 2017 by Ganesh2VL
trancexx Posted April 2, 2017 Posted April 2, 2017 9 hours ago, Ganesh2VL said: @Trancexx, my requirement is simple and straight forward but don't know exactly what to do(Just started learning AUTOIT). I want to upload a .txt file to a https web application. Wanna automate the daily task of login to a website and upload a file from local folder. Steps: 1. Open IE with URL, Login web application 2. Redirect to particular page 3. Click browse button to open the "file chooser window" and then select the input file from the given path. 4. Click upload button and wait until the process complete 5. Close the IE. What I meant is that you don't need to use browser to upload file, nor to login, nor to redirect. To provide "more info" means that you should post URL of the service (application), or at least something that isn't as obvious as your "more info". ♡♡♡ . eMyvnE
Xandy Posted April 2, 2017 Posted April 2, 2017 (edited) Pay special attention to the ftp_send_screenshot() function, Everything you need to connect and FTP is there: Project upgraded here : Edited April 3, 2017 by Xandy Now the script is even more powerful, mwha ha ha Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker)
Ganesh2VL Posted April 3, 2017 Author Posted April 3, 2017 14 hours ago, trancexx said: What I meant is that you don't need to use browser to upload file, nor to login, nor to redirect. To provide "more info" means that you should post URL of the service (application), or at least something that isn't as obvious as your "more info". Its an intranet web application can't share the URL. I have clearly pointed that it's a https web application and we have no option for FTP/DB level backend data processing due to limitation. Anyway, i have managed to automate the task. Thanks for the discussion.
Ganesh2VL Posted April 3, 2017 Author Posted April 3, 2017 10 hours ago, Xandy said: Pay special attention to the ftp_send_screenshot() function, Everything you need to connect and FTP is there: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=System\FTPScreen 2.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;***************************************** ;FTP_Screen.au3 v1 by Xandy ;Created with ISN AutoIt Studio v. 1.01 ;***************************************** #include <FTPEx.au3> #include <MsgBoxConstants.au3> #include <ScreenCapture.au3> #include <Misc.au3> #include <GUIConstants.au3> #include <File.au3> #include "System\Include\TTS.au3" HotKeySet("^{PAUSE}", "_exit_hotkey") OnAutoItExitRegister("_exit_cleanup") ; Convenient formated Script name Global $gScript_name = StringTrimRight(@ScriptName, 4) Global $gSetting_screenshot_counter_max = 9999999 Enum $eSetting_ftp_server, _ $eSetting_ftp_username, _ $eSetting_ftp_password, _ $eSetting_ftp_max Global $aSetting_ftp_name[$eSetting_ftp_max] $aSetting_ftp_name[$eSetting_ftp_server] = "Server: " $aSetting_ftp_name[$eSetting_ftp_username] = "Username: " $aSetting_ftp_name[$eSetting_ftp_password] = "Password: " Global $gPath_ftp_settings = @MyDocumentsDir & "\Songersoft\" & $gScript_name & "\FTP_Settings.txt" Global $gVoice = _StartTTS() Global $ghOpen = Null Global $ghConn = Null Enum $eMouse_coord_mode_relative, $eMouse_coord_mode_absolte Opt("MouseCoordMode", $eMouse_coord_mode_relative) Opt("SendKeyDelay", 9) Opt("SendKeyDownDelay", 5) Enum $eSetting_chatbox_pos_x, $eSetting_chatbox_pos_y, $eSetting_screenshot_counter main() Func main() $ghGui = GUICreate(@ScriptName, 320, 120) ; Load FTP settings $aSetting_ftp = ftp_load_settings($ghGui) GUICtrlCreateLabel("CTRL + F12: Selected Window to FTP", 5, 25, 320, 20) GUICtrlCreateLabel("CTRL + ALT + SHIFT + S: Selected Window to Disk", 5, 45, 320, 20) ; Used to insert referance to screenshot on server GUICtrlCreateLabel("F10: Send Clipboard keystrokes", 5, 65, 320, 20) GUISetState() Local $aSetting = load() Local $screenshot_path = @ScriptDir & "\Screenshots\" Local $screenshot_name = "Screenshot_" Local $screenshot_count = 0 Local $screenshot_type = ".png" Do $msg = GUIGetMsg() ; CTRL Pressed If _IsPressed('11') Then; CTRL ; Upload Window Screenshot to Website If _IsPressed('7B') Then; F12 $hWnd_selected = WinGetHandle("") ftp_send_screenshot($hWnd_selected, $aSetting_ftp, 0, $aSetting) _Speak($gVoice, "Uploaded Selected") keyreleased('7B') EndIf If _IsPressed('10') Then; SHIFT If _IsPressed('12') Then; ALT ; Save selected to disk If _IsPressed('53') Then; S $hWnd_selected = WinGetHandle("") _Speak($gVoice, "Saved") $screenshot_count = screenshot($hWnd_selected, $screenshot_path, $screenshot_name, $screenshot_count, $screenshot_type) keyreleased('53'); S EndIf; ispressed(S) EndIf; _IsPressed(12) ALT EndIf; _IsPressed(12) SHIFT ; Record the position of a Chatbox If _IsPressed('47') Then; G $aSetting[0] = MouseGetPos(0) $aSetting[1] = MouseGetPos(1) _Speak($gVoice, "Saved") keyreleased('47') EndIf EndIf; _IsPressed('11') ; Send Clipboard If _IsPressed('79') Then; F10 _SendEx(ClipGet()) keyreleased('79'); F10 EndIf Until $msg = $GUI_EVENT_CLOSE save($aSetting) EndFunc ;==>main Func screenshot($hWnd, $screenshot_path, $screenshot_name, $screenshot_count, $screenshot_type) DirCreate($screenshot_path) out("Path: " & $screenshot_path & $screenshot_name & $screenshot_count & $screenshot_type) _ScreenCapture_CaptureWnd($screenshot_path & $screenshot_name & $screenshot_count & $screenshot_type, _ $hWnd, _ 0, _ 0, _ - 1, _ - 1, _ 0) $screenshot_count += 1 Return $screenshot_count EndFunc ;==>screenshot Func ftp_send_screenshot($hWin, $aSetting_ftp, $Method_file_name, ByRef $aSetting, $collection_name = "lol"); setting has counter to be saved Local $hOpen = _FTP_Open('AutoIt Control') $error = @error If $hOpen = 0 Then _Speak($gVoice, "FTP Open Error") EndIf Local $hConn = _FTP_Connect($hOpen, $aSetting_ftp[$eSetting_ftp_server], $aSetting_ftp[$eSetting_ftp_username], $aSetting_ftp[$eSetting_ftp_password]) $error = @error If $hConn = 0 Then _Speak($gVoice, "FTP Connect Error") EndIf If $error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR= ' & $error) Return EndIf ; Local file_path to store screenshot $file_path = @ScriptDir & "\Screenshot.jpg" ; Capture the screen to local file_path _ScreenCapture_CaptureWnd($file_path, _ $hWin, _ 0, _ 0, _ - 1, _ - 1, _ 0) ; Make Window Title Local $win_title = WinGetTitle($hWin) ; Add win_title to path ;Local $ftp_path = $win_title Local $ftp_path = $collection_name ; Create FTP win_title folder _FTP_DirCreate($hConn, $ftp_path) ; Add FTP filename $ftp_path &= "/s_" & $aSetting[$eSetting_screenshot_counter] & ".jpg" ; Upload local screenshot file $file_put = _FTP_FilePut($hConn, $file_path, $ftp_path) out("ftp_filePut: " & $file_put) out("FTP PATH: " & $ftp_path) $url_path = "http://songersoft.com/downloads/screenshots/" & $ftp_path ; Put the URL in Clipboard ClipPut($url_path) out("FTP_Close($hConn): " & _FTP_Close($hConn)) out("FTP_Close($hOpen): " & _FTP_Close($hOpen)) setting_incroment_screenshot_counter($aSetting, $gSetting_screenshot_counter_max) EndFunc ;==>ftp_send_screenshot Func setting_incroment_screenshot_counter(ByRef $aSetting, $max) $aSetting[$eSetting_screenshot_counter] += 1 If $aSetting[$eSetting_screenshot_counter] > $max Then $aSetting[$eSetting_screenshot_counter] = 0 EndFunc ;==>setting_incroment_screenshot_counter Func out($output = "", $timeout = 0);debug tool ConsoleWrite(@CRLF & $output);to console new line, value of $output ;MsgBox(0, @ScriptName, $output, $timeout, $ghGui) EndFunc ;==>out Func keyreleased($_key1, $_key2 = "", $_key3 = "", $_key4 = "") While _IsPressed($_key1) Or _IsPressed($_key2) Sleep(20) WEnd While _IsPressed($_key3) Or _IsPressed($_key4) Sleep(20) WEnd EndFunc ;==>keyreleased Func _exit_hotkey() Exit EndFunc ;==>_exit_hotkey Func _SendEx($sKey, $raw = 0, $modup = 0);when this function is called control, shift, and alt must be released before $ss keys are sent If $modup = 0 Then While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") Sleep(20) WEnd EndIf Send($sKey, $raw) EndFunc ;==>_SendEx Func read_chunk($file); Remove Label from File Line Label Data pair. Local $chunk = FileReadLine($file) If @error <> 0 Then Return "File EOF" EndIf Local $chunk_po = StringInStr($chunk, ": "); Find the string position of the first ": " Return StringMid($chunk, $chunk_po + 2); Return String 2 spaces right from the chunk_po EndFunc ;==>read_chunk Func load() ; chatbox x ; y, ; gScreenshot_counter Local $aSetting[3] $file = FileOpen(@ScriptDir & "\Settings.txt") For $i = 0 To UBound($aSetting) - 1 $aSetting[$i] = read_chunk($file) Next FileClose($file) If $aSetting[$eSetting_screenshot_counter] = "" Then $aSetting[$eSetting_screenshot_counter] = 0 Return $aSetting EndFunc ;==>load Func save($aSetting) Local $aSetting_name = ["Chatbox_x: ", "Chatbox_y: ", "$gScreenshot_counter: "] $file = FileOpen(@ScriptDir & "\Settings.txt", BitOR($FO_OVERWRITE, $FO_CREATEPATH)) For $i = 0 To UBound($aSetting) - 1 FileWriteLine($file, $aSetting_name[$i] & $aSetting[$i]) Next FileClose($file) EndFunc ;==>save Func _exit_cleanup() out("Exit Cleanup()") out("FTP_Close($ghConn): " & _FTP_Close($ghConn)) out("FTP_Close($ghOpen): " & _FTP_Close($ghOpen)) EndFunc ;==>_exit_cleanup Func ftp_load_settings($phGui, $filepath = $gPath_ftp_settings) ; As many settings as we have names for Local $aSetting_ftp[UBound($aSetting_ftp_name)] If FileExists($filepath) = 1 Then ; Load FTP Setting File $file = FileOpen($filepath) For $i = 0 To $eSetting_ftp_max - 1 $aSetting_ftp[$i] = read_chunk($file) Next Else ; Make Blank FTP Setting File $file = FileOpen($filepath, BitOR($FO_OVERWRITE, $FO_CREATEPATH)) For $i = 0 To $eSetting_ftp_max - 1 FileWriteLine($file, $aSetting_ftp_name[$i]) Next If $file > -1 Then MsgBox(0, "Alert", "Created Blank FTP Setting File: " & @CRLF & $gPath_ftp_settings, 4, $phGui) ShellExecute($filepath) Exit Else MsgBox(0, "Alert", "Unable to Create Blank FTP Setting File: " & @CRLF & $gPath_ftp_settings, 4, $phGui) EndIf EndIf; fileexist(filepath) FileClose($file) Return $aSetting_ftp EndFunc ;==>ftp_load_settings Package uses TTS.au3 by Beege: To actually FTP with my code you need to have FTP settings stored at MyDocuments\Songersoft\FTP_Screen\FTP_Settings.txt It will prompt you, create the file, and open it. It is up to you to fill in your server IP, FTP_Username, FTP_Username_Password and save the FTP_Setting.txt file. Make sure the datas begin with a ": " to separate the data from the label. Example FTP_Settings.txt Server: 0.0.0.0 Username: FTP_USERNAME Password: USER_PASSWORD After saving the FTP_Settings you will need to rerun the program. FTP_Screen.zip @Xandy , Thanks a lot for sharing the code. Is it possible to use the same code on FTPS/SFTP based ftp connections ? I have a task to automate the file download process from SFTP ftp connection.
Xandy Posted April 3, 2017 Posted April 3, 2017 Based on your reply to Trancexx, I'm not sure _FTP_Connect will work for you. I really have no idea. Why don't you give it a go? Either run my code with your settings, or see if you can _FTP_Connect based on my code example. I have no idea man. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker)
Xandy Posted April 3, 2017 Posted April 3, 2017 (edited) Tell you what I'd be super pissed off if I paid for https and my scripts didn't work on it. Edited April 3, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker)
Ganesh2VL Posted April 3, 2017 Author Posted April 3, 2017 4 minutes ago, Xandy said: Based on your reply to Trancexx, I'm not sure _FTP_Connect will work for you. I really have no idea. Why don't you give it a go? Either run my code with your settings, or see if you can _FTP_Connect based on my code example. I have no idea man. I have asked for an another task. As u said will try with your code for SFTP connection file download. Thanks @xandy.
trancexx Posted April 3, 2017 Posted April 3, 2017 39 minutes ago, Ganesh2VL said: Its an intranet web application can't share the URL. I have clearly pointed that it's a https web application and we have no option for FTP/DB level backend data processing due to limitation. Anyway, i have managed to automate the task. Thanks for the discussion. That's great! Source of the page would be enough in that case. ♡♡♡ . eMyvnE
Xandy Posted April 3, 2017 Posted April 3, 2017 (edited) @Ganesh2VL How did it go? Did my FTP system work on your web storage? I heavily upgraded the source code too if you're actually interested in the FTP screenshot program. Edited April 3, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker)
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