#205713 - 2012-09-10 06:25 PM
copying files to remote server
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Hi Guys,
I'm trying to write a script to copy files to a group of servers. I apologize if there already is a UDF for this, but the proxy server here at work apparently renders the UDF list as blank.
I have a group of Windows 2008 R2 servers. I have placed the files in c:\temp. I also have two ini files in the same location. One has a list of all the computers in the local group and the other has a list of the files to be copied.
Examples: computers.ini
[computers]
comp1=server-name1
comp2=server-name2
comp3=another-server
files.ini[Files]
file1=jdk-6u35-windows-i586.exe
file2=visioviewer.exe
I'm trying to use:
Break On
Dim $SO
$SO = SetOption('Explicit', 'On')
$SO = SetOption('NoMacrosInStrings', 'On')
Dim $strWks, $strFile, $colFiletoSend
Dim $strComps, $colComps, $objComp, $objFSO
Dim $intErr, $objFile, $strFileName, $strRemotePath
$strFile = "c:\temp\files.ini"
$strComps = "c:\temp\computers.ini"
$colComps = Split(ReadProfileString($strComps,"computers",""),chr(10))
For each $objComp in $colComps
If $objComp <> ""
$strWks = ReadProfileString(strComps,"computers",$objComp)
$colFiletoSend = Split(ReadProfileString($strFile,"Files",""),chr(10))
cd "c:\temp"
$strRemotePath = "\\" + $strWks + "\c$\temp"
$objFSO = CreateObject("Scripting.FileSystemObject)
For each $objFile in $colFiletoSend
If $objFile <> ""
$strFileName = ReadProfileString($strFile,"Files",$objFile)
$intErr = $objFSO.CopyFile($strFileName,$strRemotePath)
EndIF
Next
EndIf
Next
When attempting the copy, I'm getting: COM exception error "CopyFile" <<null> - <null>> [-2147352567/80020009]
If I just do from a command prompt in c:\temp:copy jdk-6u35-windows-i586.exe \\server-name1\c$\temp it works. Any ideas what I am doing wrong, or a better approach?
Thanks
|
Top
|
|
|
|
#205716 - 2012-09-10 07:17 PM
Re: copying files to remote server
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Also...This line has a typo (missing a $)
$strWks = ReadProfileString(strComps,"computers",$objComp) Should be...
$strWks = ReadProfileString($strComps,"computers",$objComp)
|
Top
|
|
|
|
#205717 - 2012-09-10 07:28 PM
Re: copying files to remote server
[Re: ShaneEP]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
I'll give that a try tomorrow. It's been a while and the manual didn't say I could use copy to copy to a remote system. (missing $ was just a typo - I can't cut and paste; everything has to be re-typed)
|
Top
|
|
|
|
#205718 - 2012-09-10 07:33 PM
Re: copying files to remote server
[Re: BradV]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
This seemed to work ok for me.
Break On
$strFile = "c:\temp\files.ini"
$strComps = "c:\temp\computers.ini"
$colComps = Split(ReadProfileString($strComps,"computers",""),chr(10))
For each $objComp in $colComps
If $objComp <> ""
$strWks = ReadProfileString($strComps,"computers",$objComp)
$colFiletoSend = Split(ReadProfileString($strFile,"Files",""),chr(10))
$strRemotePath = "\\" + $strWks + "\c$\temp"
For each $objFile in $colFiletoSend
If $objFile <> ""
$strFileName = "C:\Temp\"+ReadProfileString($strFile,"Files",$objFile)
Copy $strFileName $strRemotePath
EndIF
Next
EndIf
Next
|
Top
|
|
|
|
#205739 - 2012-09-12 12:37 PM
Re: copying files to remote server
[Re: ShaneEP]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Yes, I kept the cd in. Worked perfectly. Maybe we should suggest a change to the manual to add that copy to a remote system also works?
Thanks Shane!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|