Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Copy to UNC path copies empty 1

Status
Not open for further replies.

baldwintm

MIS
Sep 25, 2008
9
US
I am creating a script that will automatically deploy a common *.pac file (for proxy settings) to four different webservers across two datacenters.

Everything in the script works, except the file copy.
The testdeploydc.pac and testdeploysdc.pac files are 8k, but they copy to the destination folders as empty files.

Another thing to probably note is that this script is being "runas" another user (runas user with privs to write to destination).

How do I get these to copy correctly?

Script follows:


Code:
Const ForReading = 1
Const ForWriting = 2

strFileSourcePath = "proxy.pac"
strFileTargetPathDC = "testdeploydc.pac"
strFileTargetPathSDC = "testdeploysdc.pac"
strFileTargetPath = "E$\webroot\proxy\testdeploy.pac"
strPathDC12p = "\\server12p\"
strPathDC13p = "\\server13p\"
strPathSDC14p = "\\server14p\"
strPathSDC15p = "\\server15p\"
added = false

on error resume next

Set objFSOSource = CreateObject("scripting.filesystemobject")
Set objFSOTargetDC = CreateObject("scripting.filesystemobject")
Set objFSOTargetSDC = CreateObject("scripting.filesystemobject")

Set objFilesSource = objFSOSource.OpenTextFile(strFileSourcePath,ForReading,True,0) 
Set objFilesTargetDC = objFSOTargetDC.OpenTextFile(strFileTargetPathDC,ForWriting,True,0) 
Set objFilesTargetSDC = objFSOTargetSDC.OpenTextFile(strFileTargetPathSDC,ForWriting,True,0)
Set fso = CreateObject("Scripting.FileSystemObject")

Do While objFilesSource.AtEndOfStream <> True
  strCurrentLine = objFilesSource.ReadLine

  if ((InStr(1,strCurrentLine,"use_proxy",1) > 0) AND (added = false)) then
    objFilesTargetDC.WriteLine "  var use_proxy = proxy_dc;"
    objFilesTargetSDC.WriteLine "  var use_proxy = proxy_sdc;"
    added = true
  else
    objFilesTargetDC.WriteLine strCurrentLine
    objFilesTargetSDC.WriteLine strCurrentLine
  end if

Loop

objFilesSource.Close
objFilesTargetDC.Close
objFilesTargetSDC.Close

Set objFSOSource = Nothing
Set objFSOTargetDC = Nothing
Set objFSOTargetSDC = Nothing

if fso.FileExists("testdeploydc.pac") then
    fso.CopyFile "testdeploydc.pac", strPathDC12p & strFileTargetPath
    fso.CopyFile "testdeploydc.pac", strPathDC13p & strFileTargetPath
else
    wscript.echo "testdeploydc.pac does not exist"
end if

if fso.FileExists("testdeploysdc.pac") then
    fso.CopyFile "testdeploysdc.pac", strPathSDC14p & strFileTargetPath
    fso.CopyFile "testdeploysdc.pac", strPathSDC15p & strFileTargetPath
else
    wscript.echo "testdeploysdc.pac does not exist"
end if

Set fso = Nothing

Wscript.echo "deployment finished"

If Err.Number <> 0 Then
    WScript.Echo "Error: " & Err.Number & "; Description: " &  Err.Description
    Err.Clear
End If
 
I know that the .CopyFile will fail if you try to overwrite an existing file which is 'Read only', so make sure that is not a problem. Either the Read only attribute is set, or you don't have enough privs perhaps.
 
Anyway why so many Scripting.FileSystemObject objects.
You only need one.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The script is working now. Before, was just doing "runas /user:foodomain\me myscript.vbs" once I added the /env option, the script works great.

PHV:
I just pulled it from another script that someone else wrote, I'll delete them all but one FSO.

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top