Page 1 of 1 1
Topic Options
#205713 - 2012-09-10 06:25 PM copying files to remote server
BradV Offline
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
 Code:
[computers]
comp1=server-name1
comp2=server-name2
comp3=another-server


files.ini
 Code:
[Files]
file1=jdk-6u35-windows-i586.exe
file2=visioviewer.exe


I'm trying to use:
 Code:
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:
 Code:
COM exception error "CopyFile" <<null> - <null>> [-2147352567/80020009]


If I just do from a command prompt in c:\temp:
 Code:
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
#205715 - 2012-09-10 07:11 PM Re: copying files to remote server [Re: BradV]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Have you tried just using the built in kix version of COPY rather than the FSO com object?
Top
#205716 - 2012-09-10 07:17 PM Re: copying files to remote server [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Also...This line has a typo (missing a $)

 Code:
$strWks = ReadProfileString(strComps,"computers",$objComp)

Should be...
 Code:
$strWks = ReadProfileString($strComps,"computers",$objComp)

Top
#205717 - 2012-09-10 07:28 PM Re: copying files to remote server [Re: ShaneEP]
BradV Offline
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 Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
This seemed to work ok for me.

 Code:
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
#205719 - 2012-09-10 07:35 PM Re: copying files to remote server [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Oh and make sure to turn on NOVARSINSTRINGS as well. The dollar sign in the share path might be giving you problems. I just tested to a non-hidden \\server\share type directory and it worked fine.
Top
#205720 - 2012-09-10 07:51 PM Re: copying files to remote server [Re: ShaneEP]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shane appears to hard code the paths whereas BradV infers from current working directory. I see a CD but the current working drive might be different.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#205724 - 2012-09-10 08:34 PM Re: copying files to remote server [Re: Les]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Oh yes, forgot to mention that one.
Top
#205739 - 2012-09-12 12:37 PM Re: copying files to remote server [Re: ShaneEP]
BradV Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org