Copy remote file to local machine in VB

Closed
Simmi - Oct 7, 2009 at 05:44 AM
 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.
Related:

2 responses

Blocked Profile
Oct 7, 2009 at 08:21 AM
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.
2
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.
0
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
how to connect a vb program to system file in (wordpad)
0