Mornin' all,

I need to copy all the .xml files in a source folder on a server to a target
folder on a client machine. The script will be run from the client machine.

I can't figure out how to do this at all, I can only do it by specifying the
exact filename. If anyone can offer any help on this, I'd be very grateful.

Cheers,
Foss

PLEASE IGNORE THIS COPY! by Foss

Foss
Mon Dec 06 05:35:06 CST 2004

I posted twice by mistake.

Sorry!

Re: Copy all files of type .xml by McKirahan

McKirahan
Mon Dec 06 05:47:08 CST 2004

"Foss" <Foss@discussions.microsoft.com> wrote in message
news:692B333D-90FC-4B64-B57A-73A36E3EE888@microsoft.com...
> Mornin' all,
>
> I need to copy all the .xml files in a source folder on a server to a
target
> folder on a client machine. The script will be run from the client
machine.
>
> I can't figure out how to do this at all, I can only do it by specifying
the
> exact filename. If anyone can offer any help on this, I'd be very
grateful.
>
> Cheers,
> Foss

Is the use of command line FTP an option?

You can generate a list of files in the folder then get them.



Re: Copy all files of type .xml by Foss

Foss
Mon Dec 06 05:55:02 CST 2004

Hi there,

I'm not sure, I've never tried.

Have you got an example I could test?

Cheers,
Pete



"McKirahan" wrote:

> "Foss" <Foss@discussions.microsoft.com> wrote in message
> news:692B333D-90FC-4B64-B57A-73A36E3EE888@microsoft.com...
> > Mornin' all,
> >
> > I need to copy all the .xml files in a source folder on a server to a
> target
> > folder on a client machine. The script will be run from the client
> machine.
> >
> > I can't figure out how to do this at all, I can only do it by specifying
> the
> > exact filename. If anyone can offer any help on this, I'd be very
> grateful.
> >
> > Cheers,
> > Foss
>
> Is the use of command line FTP an option?
>
> You can generate a list of files in the folder then get them.
>
>
>

Re: Copy all files of type .xml by McKirahan

McKirahan
Mon Dec 06 07:39:03 CST 2004

"Foss" <Foss@discussions.microsoft.com> wrote in message
news:38625AEE-8E4F-4FC8-9E96-60CA4B1776C5@microsoft.com...
> Hi there,
>
> I'm not sure, I've never tried.
>
> Have you got an example I could test?
>
> Cheers,
> Pete
>
>
>
> "McKirahan" wrote:
>
> > "Foss" <Foss@discussions.microsoft.com> wrote in message
> > news:692B333D-90FC-4B64-B57A-73A36E3EE888@microsoft.com...
> > > Mornin' all,
> > >
> > > I need to copy all the .xml files in a source folder on a server to a
> > target
> > > folder on a client machine. The script will be run from the client
> > machine.
> > >
> > > I can't figure out how to do this at all, I can only do it by
specifying
> > the
> > > exact filename. If anyone can offer any help on this, I'd be very
> > grateful.
> > >
> > > Cheers,
> > > Foss
> >
> > Is the use of command line FTP an option?
> >
> > You can generate a list of files in the folder then get them.
> >
> >
> >

Try this; watch for word-wrap.

Change "cDOM" and "cUSR" and "cPWD" for your needs.
("cDOM" can be a domain or an IP address.)


Option Explicit
'****
'* This VBS (Visual Basic Script) program does the following:
'* 1) Creates "ftp.ftp" to download "dir".
'* Deletes "ftp.ftp" after the download.
'* 2) Creates "ftp.ftp" to download files.
'* Deletes "ftp.ftp" after the downloads.
'* 3) Appends "ftp.log" with "FTP" activity.
'****
'*
'* Declare Constants
'*
Const cVBS = "ftp.vbs" '= HTA program
Const cFTP = "ftp.ftp" '= FTP filename
Const cLOG = "ftp.log" '= Log filename
Const cWSS = "%comspec% /C " '= FTP execute
Const cFOL = "C:\Temp\ftp\" '= local folder
Const cDIR = "/temp/" '= remote folder
Const cEXT = ".xml" '= file extension
'Const cDOM = "www.domain.org" '= FTP Domain
Const cDOM = "127.0.0.1" '= FTP Domain
Const cUSR = "user" '= FTP Username
'Const cPWD = "pass" '= FTP Password
'*
'* Declare Globals
'*
Dim arrFIL()
Dim intFIL
intFIL = 0
Dim strFIL
'*
'* Declare Object
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*
'* Delete Files
'*
If objFSO.FileExists(cFTP) Then objFSO.DeleteFile(cFTP)
If objFSO.FileExists(cLOG) Then objFSO.DeleteFile(cLOG)
'*
'* doFTP
'*
Call doFTP("Dir")
If intFIL > 0 Then
Call doFTP("Get")
End If
'*
'* Destroy Object
'*
Set objFSO = Nothing
'*
MsgBox intFIL & " file(s) downloaded.",vbInformation,cVBS

Sub doFTP(Action)
'****
'* doFTP("Dir") = Directory listing.
'* doFTP("Get") = Download file(s).
'****
'*
'* Declare Variables
'*
Dim arrOTF
Dim intOTF
Dim strOTF
'*
'* Prepare ".ftp"
'*
strOTF = "open " & cDOM & vbCrLf
strOTF = strOTF & cUSR & vbCrLf
strOTF = strOTF & cPWD & vbCrLf
strOTF = strOTF & "hash" & vbCrLf
strOTF = strOTF & "ascii" & vbCrLf
If Action = "Dir" Then
strOTF = strOTF & "dir " & cDIR & vbCrLf
ElseIf Action = "Get" Then
strOTF = strOTF & "cd " & cDIR & vbCrLf
For intFIL = 0 To UBound(arrFIL)
strFIL = arrFIL(intFIL)
strOTF = strOTF & "get " & strFIL & " " & cFOL & strFIL & vbCrLf
Next
End If
strOTF = strOTF & "close" & vbCrLf
strOTF = strOTF & "bye" & vbCrLf
'*
If Not objFSO.FolderExists(cFOL) Then
MsgBox "Download folder does not exist!",vbExclamation,cVBS
WScript.Quit
End If
'*
'* Create ".ftp"
'*
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cFTP,2,true)
objOTF.WriteLine(strOTF)
objOTF.Close()
Set objOTF = Nothing
'*
'* Transfer
'*
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
objWSS.Run cWSS & " ftp -i -s:" & cFTP & " >> " & cLOG,2,True
Set objWSS = Nothing
'*
'* Delete ".ftp"
'*
If objFSO.FileExists(cFTP) Then objFSO.DeleteFile(cFTP)
'*
'* Find Files in Log
'*
If Not Action = "Dir" Then Exit Sub
Set objOTF = objFSO.OpenTextFile(cLOG,1)
strOTF = objOTF.ReadAll()
'WScript.Echo strOTF
objOTF.Close()
Set objOTF = Nothing
'*
arrOTF = Split(strOTF,vbCrLf)
For intOTF = 0 To UBound(arrOTF)
strOTF = arrOTF(intOTF)
strOTF = Replace(strOTF,vbCr,"")
If Mid(strOTF,3,1) = "-" _
And Mid(strOTF,6,1) = "-" _
And Mid(strOTF,13,1) = ":" _
And InStr(strOTF,"<DIR>") = 0 _
And LCase(Right(strOTF,4)) = cEXT Then
intFIL = intFIL + 1
ReDim Preserve arrFIL(intFIL)
strFIL = Mid(strOTF,InStrRev(strOTF," ")+1)
arrFIL(intFIL) = strFIL
End If
Next
End Sub


If you don't want to hardcode the password then use InputBox() to prompt for
it each time by inserting the following under " Dim strFIL":
Dim strPWD
'*
'* Password Check
'*
strPWD = InputBox("Enter FTP Password")
If strPWD = "" Then
MsgBox "Password is required!",vbExclamation,cVBS
WScript.Quit
End If
and changing:
strOTF = strOTF & cPWD & vbCrLf
to:
strOTF = strOTF & strPWD & vbCrLf



Re: Copy all files of type .xml by McKirahan

McKirahan
Mon Dec 06 07:49:05 CST 2004

"McKirahan" <News@McKirahan.com> wrote in message
news:XhZsd.199262$HA.114329@attbi_s01...

[snip]

The number of " file(s) downloaded." is off by one.

Add the following line
If intFIL > 0 Then intFIL = intFIL - 1
as the last statement under the "ElseIf" (just before the "End If").



Re: Copy all files of type .xml by Steve

Steve
Mon Dec 06 20:26:28 CST 2004

I didn't see if you require the use of FTP, but if not and both are windows
workstations that you can access and the folder is shared somehow, why can
you just do the following:

@ECHO OFF
set source=\\server1\share
set target=C:\mytargetfolder
copy %source%\*.xml %target%

--
Steve Seguis - MCSE, MS-MVP, SCJP
SCRIPTMATION
Automating the Enterprise
http://www.scriptmation.com

"Foss" <Foss@discussions.microsoft.com> wrote in message
news:38625AEE-8E4F-4FC8-9E96-60CA4B1776C5@microsoft.com...
> Hi there,
>
> I'm not sure, I've never tried.
>
> Have you got an example I could test?
>
> Cheers,
> Pete
>
>
>
> "McKirahan" wrote:
>
>> "Foss" <Foss@discussions.microsoft.com> wrote in message
>> news:692B333D-90FC-4B64-B57A-73A36E3EE888@microsoft.com...
>> > Mornin' all,
>> >
>> > I need to copy all the .xml files in a source folder on a server to a
>> target
>> > folder on a client machine. The script will be run from the client
>> machine.
>> >
>> > I can't figure out how to do this at all, I can only do it by
>> > specifying
>> the
>> > exact filename. If anyone can offer any help on this, I'd be very
>> grateful.
>> >
>> > Cheers,
>> > Foss
>>
>> Is the use of command line FTP an option?
>>
>> You can generate a list of files in the folder then get them.
>>
>>
>>