Copy remote file to local machine in VB [Closed]

 Bruce -

Am new to VbScript, now I need to write a vbscript to copy a file from a remote(mainly non-windows) machine to my local machine at a given location.
Please can you help me with it.

2 replies

Dear Simmi,

Below is a sample that can help you in undertaking the task:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sSrcDir : sSrcDir = "//server\share"
Dim sDstDir : sDstDir = oFS.GetAbsolutePathName( "your\folder" ) & "\"

WScript.Echo "sSrcDir:", sSrcDir
WScript.Echo "sDstDir:", sDstDir

If Not oFS.FolderExists( sDstDir ) Then oFS.CreateFolder sDstDir

Dim oSrcFiles : Set oSrcFiles = oFS.GetFolder( sSrcDir ).Files
Dim oFile, sFSpec
For Each oFile In oSrcFiles
WScript.Echo "Src ", oFile.Path
sFSpec = sDstDir & oFile.Name
If oFS.FileExists( sFSpec ) Then
WScript.Echo "Fnd ", sFSpec
If oFile.DateLastModified > oFS.GetFile( sFSpec ).DateLastModified Then
WScript.Echo "Cpy (D)", sFSpec
oFile.Copy sFSpec
End If
WScript.Echo "Cpy (N)", sFSpec
oFile.Copy sFSpec
End If

Thanks in advance.
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 3538 users have said thank you to us this month

when I am trying to copy file from server it is throwing an error i.e. path is not found and it is required credentials to copy file from remote server how I can use above code if would have to use credentials. Please reply.
All of the information and events that you do should all be stored in the <a href="">local directory</a> as well. So that if you need to go back and look at something, it's right there for you.
how to connect a vb program to system file in (wordpad)