Forum Discussion

nassim's avatar
nassim
Occasional Contributor
14 years ago

How to make a network connection with test complete

Hi,

I need to make a connection with TestComplete to a server (to which I make a connection normally with WinSCP und protocol SFTP out of test complete). Then, I should copy a tab seperated file from the server to my local for later searching in the file. Does anyone have an idea how to start? I use VBScript. However, I do not know also if a script in another Testcomplete scripting language can be called from my VBScript?

Thank you,

Nassim

5 Replies

  • You can start by automating the SFTP process through WinSCP scripting or by calling external commands from your TestComplete VBScript. Once the file is downloaded to your local system, you can use VBScript file handling methods to open and search the tab separated data. Make sure the server path, login credentials, and access permissions are correctly configured before running the test. In larger environments, having reliable Networking Infrastructure Solutions helps maintain smooth communication between test systems and remote servers, reducing connection issues during automation tasks. This approach should make your workflow easier to manage and troubleshoot.

  • Hi Vova,



    Here you are:

    function Test()

    {

      var strWinSCP = "C:\\Program Files\\WinSCP\\winscp.com";

      var strLogFile = "C:\\Test\\winscplog.xml";



      var oShell = Sys.OleObject("WScript.Shell");

      var oExec = oShell.Exec("\"" + strWinSCP + "\" /log=" + strLogFile);



      // Feed commands to WinSCP

      oExec.StdIn.WriteLine("option batch on");

      oExec.StdIn.WriteLine("option confirm off");

      oExec.StdIn.WriteLine("open session_URL_or_stored_session");

      oExec.StdIn.WriteLine("get MyFile.csv C:\\Test\\");

      oExec.StdIn.WriteLine("exit");



      // Wait until the WinSCP execution is completed

      while (oExec.Status == 0) Delay(100);



      if (oExec.ExitCode == 0)

      {

        Log.Message("File download completed successfully.");

      }

      else

      {

        Log.Error("WinSCP exited with error code " + oExec.ExitCode +

                  ". See Additional Information for details.",

                  aqFile.ReadWholeTextFile(strLogFile, aqFile.ctUTF8));

      }

    }
    • srini_molleti's avatar
      srini_molleti
      New Contributor

       

      Hi Helen,

       

      In my case first I need to connect to a server using WinSCP. How to provide server name, username and password as input to the connection. Then I need to copy a file to the server, wait for few seconds and get the created output file to the local. 

      Could you please help me in writing a JavaScript code to achieve this.


      Thanks for your help.

  • vladm's avatar
    vladm
    Occasional Contributor

    Hi, Helen.


    Can you give such code example but in JS.


    Thanks. 

  • Hi Nassim,



    Neither VBScript, nor Windows, nor TestComplete has built-in SFTP scripting functionality, so you'll need a third-party utility or scripting component for this purpose. WinSCP will do as you already use it. I see that WinSCP supports command-line automation, so you can automate downloading the file by passing appropriate commands to WinSCP from your VBScript code. Here's a rough example:



    Sub Test

      Dim strWinSCP, strLogFile, oShell, oExec

     

      strWinSCP = "C:\Program Files\WinSCP\winscp.com"

      strLogFile = "C:\Test\winscplog.xml"

     

      Set oShell = CreateObject("WScript.Shell")

      Set oExec = oShell.Exec("""" & strWinSCP & """ /log=" & strLogFile)

     

      ' Feed commands to WinSCP

      With oExec.StdIn

        .WriteLine("option batch on")

        .WriteLine("option confirm off")

        .WriteLine("open session_URL_or_stored_session")

        .WriteLine("get MyFile.csv C:\Test\")

        .WriteLine("exit")

      End With

     

      ' Wait until the WinSCP execution is completed

      Do While oExec.Status = 0

        Delay(100)

      Loop

     

      If oExec.ExitCode = 0 Then

        Log.Message("File download completed successfully.")

      Else

        Call Log.Error("WinSCP exited with error code " & oExec.ExitCode & _

          ". See Additional Information for details.", _

          aqFile.ReadWholeTextFile(strLogFile, aqFile.ctUTF8))

      End If

    End Sub



    I hope this helps.