Copy remote file to local machine in VB [Closed]

- - Latest reply:  Bruce - Jan 25, 2012 at 03:16 PM
Hello,

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.
See more 

2 replies

Best answer
2
Thank you
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
Else
WScript.Echo "Cpy (N)", sFSpec
oFile.Copy sFSpec
End If
Next

Thanks in advance.

Say "Thank you" 2

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

CCM 5630 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="http://www.pinoya.com">local directory</a> as well. So that if you need to go back and look at something, it's right there for you.
0
Thank you
how to connect a vb program to system file in (wordpad)