Create Logs while transferring folder from one server to another server through vbscript
Hi I have one folder present on my server and I have created script to transfer that folder everyday to different server,What i am looking is that while transferring it should maintain logs and if any error comes then i want to send email to me ,So i should be aware that transfer got failed.Below is script I am using,Please help.
Public Str4 Public topath Public Frompath Public Filename'Values of variables setstrDriveLetter = "Z:"strRemotePath = "\\192.168.1.20\dumpsDB1"strUser = "User"strPassword = "User"strProfile = "false"' ************** Setting Network Drive **************Set objNetwork = WScript.CreateObject("WScript.Network")objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _strProfile, strUser, strPassword' ************** System Parameters ************** Frompath= strDriveLetter Filename="DB1database.dmp" topath="c:\backup\DB1Folder"Str4= "cmd /C copy " & Frompath &"\"&Filename &" " & topath 'msgbox Str4 On Error Resume Next Set oShell = CreateObject("WScript.Shell") retval = oShell.Run( Str4, 1, True) Set oShell = Nothing' ************** Deleting Network Drive **************objNetwork.RemoveNetworkDrive strDriveLetter
I would suggest using the filesystem object to do the copy in VBS rather than shelling to a command line. It's easy then to trap for errors on the copy and take action. Below is a sample of that code, without the email logic, I'll find an example of that but you would need to specify more information about your environment. For example, do you have an outgoing SMTP mail server that can be used to send the email? Does it require authentication credentials? Etc...
And a site with more comprehensive information for different situations. I would start reading after the text "Sending a text email using a remote server.":
Hi Bill I understand email part but I want to create log file also while transfer,Is it possible? Please reply asap.
Sudhanshum
ASKER
Hi Bill,
I tried ur code and its always going inside error condition,that means its not copying file and alerting that error. I am not sure why error coming because through previous code,copy working fine. Plz help
Open in new window
~bp