Forum Discussion

prasadblv's avatar
prasadblv
New Contributor
9 years ago

Not able to copy a file to shared folder which is located in another vm though it is accessible

Hi

i am trying to copy a file to a shared folder which is located in another vm but my below script is failing. Later i tried with Ranorex tool for the same and i am able to do that. Please suggest how to copy that file.

'======================================================

Dim sSourceFilePath


sSourceFilePath = "C:\Files\Test.txt"


If AddNetworkDrive("\\compname\c$\destination_Folder","Z") Then
 Log.Message("Network Drive mapped")
 call oFSO.CopyFile(sSourceFilePath,"Z:\",true)
 
 If oFSO.FileExists ("Z:\Test.txt") Then
  Log.Message("File Copied")
 else
  Log.Error("File not Copied")
 end if
Else
 Log.Message("Network Drive not mapped")
End if

 

 

Function AddNetworkDrive(sPath , sDriveLater)
  dim sUserName,sPWD,res
  sUserName = "domain\userid"
  sPWD = "********"
 
  Set oFSO = CreateObject("scripting.filesystemobject")
  Set oWshNetwork = CreateObject("WScript.Network")
  If Not oFSO.DriveExists("Z:") Then
  'aDD USER NAME AND PASSWORD
  '=========
  res = aqFileSystem.MapNetworkDrive(sDriveLater, sPath)
  If res <> 0 Then
    Log.Error(aqUtils.SysErrorMessage(res) & " Error code is " & res & ".")
  Else
    Log.Message("The connection to '" & path & "' has been established successfully.")
  End If
  '========
    If Not oFSO.DriveExists("Z:") Then
      Log.Error("Network Drive not Added")
      bFound = False
    Else
      Log.Message("Network Drive Added")
      bFound = True
    End If
  Else
    Log.Message("Netowrk Drive exists")
    'bFound = True
    Set oDrives = oWshNetwork.EnumNetworkDrives
    For i = 0 to oDrives.Count - 1 Step 2

      If oDrives.Item(i) = sDriveLater &":" Then
        sUNC = LCase(oDrives.Item(i+1))
      End If
    Next

    If sUNC = LCase(sPath) Then

      bFOund = True

    Else

    'oWshNetwork.RemoveNetworkDrive sDriveLater &":", True

    If Not oFSO.DriveExists("Z:") Then
      Log.Error("Network Drive not Added")
      bFound = False
    Else
      Log.Message("Network Drive Added")
      bFound = True
    End If
    End If
  End IF
  AddNetworkDrive = bFound
End Function

4 Replies

  • scsvel's avatar
    scsvel
    Frequent Contributor

    Did you tried with simple code, without network mapping.

     

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    oFSO.CopyFile "C:\Files\Test.txt", "\\compname\c$\destination_Folder\Test.txt", True

    If not working, try to manually MAP to the network and pass the network path and try.

     

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Even more simple one-liner that uses aqFileSystem.CopyFile() call might be considered... :)

    • prasadblv's avatar
      prasadblv
      New Contributor

      Thanks for your reply :)

      I have tried already by mapping the destination to 'Z' drive. Still i am not able to copy. Please suggest if you have any other work around for this problem.

      Note1: i am able to copy file to the parent folder of the destination folder but not to the destination folder.

      Note2: i am able to copy file to the destination folder using Ranorex code but not vbscript with testcomplete.

       

      Thanks

      Vara Prasad

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        >  i am able to copy file to the destination folder using Ranorex code but not vbscript with testcomplete.

        Check that the account used to start TestComplete has permissions (both network and on the remote system) to create files on the target remote folder.