Forum Discussion

CSL's avatar
CSL
Contributor
8 years ago

How can I copy a file to another server in javascript? The copyfile method does not cop the file.

var strServer = "VMSQA4"

strNewMachFile = "\\" + strServer + "\\D:\\ETL_FILES\\Machine\\"

aqFileSystem.CopyFile("D:\\Automation\\TestData\\ETL\\DELTA\\machine_TC2173.txt", strNewMachFile, true) 

  • Well, this is the point where I have to start wondering if it's worth scripting.  So, the question is:

     

    Why do you need to copy that file to a server location?

     

    Because the answer to that may reveal that there might be other ways of achieving the same result.  If you're new to writing automation code, JavaScript or otherwise, then I would certainly look for different ways of doing what you want to do.  As far as I can find, using the various "aq" objects available in TestComplete, there's not an easy, one line way to do this. 

     

    What you MIGHT end up doing is something like using aqFileSystem.MapNetworkDrive to map the drive to a drive letter... that has parameters to it to pass in the username and password that you want.  

     

    Then, you can copy the file using the drive letter rather than the UNC path.

     

    Then, use aqFileSystem.DisconnectNetworkDrive to remove the mapping before you move on.

     

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Change your second line...  Keep in mind that a double backslash, in JavaScript, is interpreted as a single... so if you want to actually have a double backslash, you need to double it up to 4.  See if that works for you.

     

    var strServer = "VMSQA4"

    strNewMachFile = "\\\\" + strServer + "\\D:\\ETL_FILES\\Machine\\"

    aqFileSystem.CopyFile("D:\\Automation\\TestData\\ETL\\DELTA\\machine_TC2173.txt", strNewMachFile, true) 

     

  • CSL's avatar
    CSL
    Contributor

    Thank you. I just found out that the destination folder is on a different domain, how do I pass on the user id & password? Can you give sample please? I am new in Test Complete & javascript as well.

     

    I appreciate your help.

     

    Thanks.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Well, this is the point where I have to start wondering if it's worth scripting.  So, the question is:

       

      Why do you need to copy that file to a server location?

       

      Because the answer to that may reveal that there might be other ways of achieving the same result.  If you're new to writing automation code, JavaScript or otherwise, then I would certainly look for different ways of doing what you want to do.  As far as I can find, using the various "aq" objects available in TestComplete, there's not an easy, one line way to do this. 

       

      What you MIGHT end up doing is something like using aqFileSystem.MapNetworkDrive to map the drive to a drive letter... that has parameters to it to pass in the username and password that you want.  

       

      Then, you can copy the file using the drive letter rather than the UNC path.

       

      Then, use aqFileSystem.DisconnectNetworkDrive to remove the mapping before you move on.

       

       

      • CSL's avatar
        CSL
        Contributor

        Thank you Robert, that's what I ended up doing, map the drive and it seems to be working - yay!