Jump to content

smcan

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by smcan

  1. Don't know if it would get you where you want to go but you could try using psftp.exe (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). Would need to have psftp.exe in the working directory or get it in the path of the script and you would need a separate script file for use by psftp in the working directory as well. Script file contains the commands you want to run through psftp (example.scr): cd /home/user put test.txt get test2.txt quit Would call it via autoit with: Run(@ComSpec & " /c" & "psftp.exe user@hostname -pw password -b test.scr","",@SW_HIDE) The -b test.scr is what calls the psftp script.
  2. Think I figured it out but it's not optimal. Looks like the problem is with plink.exe itself and not with the autoit code. I'm using a portable version of plink (stores keys and session info in files instead of registry) but I don't think that matters because the portable version is still based on the most recent version 0.63 of regular plink. Using Putty instead of plink produces the desired result. Not optimal as I prefer the way plink works on the command line over putty but I'll take it to get this project moving. Figured out the error that was causing plink to close using the @comspec /k instead of /c. For some reason plink was receiving a disconnect command when portqry ran but putty doesn't seem to have the same issue. Thanks again to orbs for helping me get the portqry loop working properly!
  3. I have a script that launches plink.exe followed by portqry.exe that checks to make sure the plink created tunnel has been established and then opens mstsc.exe with a preconfigured .RDP file when portqry returns successful (Thanks to orbs for helping get the portqry looping fixed). However, after the RunWait for portqry completes and exits, the running plink is also being closed and the end result is the mstsc can't connect because the tunnel is no longer there. Following is the entire script (not entirely complete and sanitized ip's/domain/accounts). Hoping somebody can advise why plink doesn't keep running? #include <GUIConstantsEx.au3> #include <EditConstants.au3> Opt("GUIOnEventMode",1) $hGUI = GUICreate("Remote Connection",205,286,192,114) $hBut1 = GUICtrlCreateButton("Launch Term1",16,48,161,49) $hBut2 = GUICtrlCreateButton("Launch Term2",16,113,161,49) GUISetState(@SW_SHOW) GUICtrlSetOnEvent($hBut1, "lnchTerm1Press") GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI") ; This while/wend keeps the gui open While 1 Sleep(10); Wend ; Functions ; If Launch term1 button is pressed func lnchTerm1Press() If lnchTerm1() Then MsgBox(0, "YIL", "Yey, we are connected!", 10) Else MsgBox(0, "SOL", "No tunnel created, sorry!", 10) Endif EndFunc ; Launch Term1 button function Func lnchTerm1() $uName = "sshuser" $pWord = "sshpass" Run("plink.exe -l " & $uName & " -pw " & $pWord & " -L 3391:192.168.50.25:3389 -P 22 -2 -C -ssh ssh.domain.tld","",@SW_SHOW) $intCtr = 1 while $intCtr < 30 $retVal = RunWait("portqry.exe -n 127.0.0.1 -e 3391","",@SW_SHOW) if $retVal = 0 Then Run("mstsc.exe Term1.RDP") Return True Else $intCtr = $intCtr + 1 EndIf WEnd Return False EndFunc ; Close all plink processes function Func PlinkClose() ;Close any open plink sessions While 1 if ProcessExists("plink.exe") Then ProcessClose("plink.exe") Else return False EndIf Wend EndFunc ; Exit program function (closes plink sessions on the way out) Func ExitGUI() PlinkClose(); Exit EndFunc
  4. Thanks for the help and this did solve my initial loop problem so I'll mark it solved and open a new topic about the running of plink not continuing to run after the running of portqry completes.
  5. Thanks for the welcome and the very helpful reply. I modified my code to match what you have and it does launch but when the portqry run closes it is also closing the plink run so when the mstsc run's, it can't connect because the tunnel has gone away. Why would the plink run close? If I comment out everything after the plink run it's keeps running. Thanks again! EDIT: No offense meant but, yeah, I get what jdelaney and you are saying about the self explanatory error but in the post previous to me posting that error, you are the one that told me to move the ExitLoop outside of the loop!
  6. Thanks for the reply! However, I just tried it and I get the error "error: 'ExitLoop' not allowed outside loop."
  7. Anyone? Here's some code I've tried (changed it around quite a bit but none of my changes have worked). As it is, it runs plink then runs portqry but only appears to iterate once and then both plink and portqry close. Also, sorry, I think I wrote putty in the orig post but I'm actually using plink. Func lnchTerm1() $qPort = 3391 $uName = "sshuser" $pWord = "sshpass" Run("plink.exe -l " & $uName & " -pw " & $pWord & " -L 3391:192.168.50.25:3389 -P 22 -2 -C -ssh ssh.domain.tld","",@SW_SHOW) $intCtr = 1 while $intCtr < 30 $retVal = RunWait("portqry.exe -n 127.0.0.1 -e 3391","",@SW_SHOW) if $retVal = 0 Then Run("mstsc.exe Term1.RDP") ExitLoop Else $intCtr = $intCtr + 1 EndIf MsgBox(0, "SOL", "No tunnel created, sorry!", 10) ExitLoop WEnd EndFunc
  8. Looking for some help in getting the microsoft utility portqry.exe to loop until it returns "LISTENING". I currently have a batch file that launches a connection to an SSH server using putty and creates a tunnel for RDP to a terminal server. I then loop portqry.exe until it is not %errorlevel% == 0. When that condition is met, it will run mstsc.exe using a preconfigured .RDP file or after 30 iterations will return an error message that the tunnel was not created. This works well but I'm looking for a more elegant solution that can be distributed to my users as an exe. I originally started trying to create this in C++ but was creating it as a console application (don't own Visual C++). Then I remembered AutoIt and that it can create GUI applications so I started working with AutoIt. I've got the beginnings of the GUI application and can successfully connect to and close the SSH session from the app but my thick skull is having a really hard time figuring out which type of loop to use for the portqry issue and what return value to check on in the loop since %errorlevel% is for batch and not AutoIt. I've read through each of the loop types in the documentation and looked at other peoples loop examples but it's just not formalizing in my brain. I know I could use sleep or something but it's not very elegant. Portqry will allow it to check for the connection in real time and continue on instead of just waiting some preset amount of time. Please be patient as I'm brand new to AutoIt and although I've done lot's of "Hello World's" in quite a few different programming and scripting languages, that's about as far as I've gone. Just to add a little clarification to all that probably unnecessary text, I know how to make portqry run in autoit but can't figure out how to loop it until a value is met before moving on to the next action.
×
×
  • Create New...