tags:

views:

27

answers:

1

I need to comeup with a vbscript to grab a file from an ftp site where the file name is in the form "vendor(date)(date)(random#).zip" . These files are updated daily so I need a regex or way to select the newest file on the server and download it. I know how to handle this on the local file system, but I don't know how to determine which file to get on a remote ftp server.

+2  A: 

Funny you posted this as I just recently had to knock out a script to do almost exactly word for word what you're asking for. Basically, all you really need to do is to have your script create an FTP command file, then call it.

Use your method of choice to create a string to hold the date in whatever format you are looking for, I called it strDate and in my case it ended up being this syntax: headerinfo.13September10 Where headerinfo is a standard file header with a number attached to it.

Write out an FTP command file:

Dim objOutStream
Set objOutStream = objFSO.OpenTextFile(strCommandFile, ForWriting, True, TristateFalse)
With objOutStream
    .WriteLine "USER xxxxxx"   ' USERNAME
    .WriteLine "xxxxxxftp"     ' Password
    .WriteLine "binary"
    .WriteLine "prompt n"
    .WriteLine "lcd " & strNetmonData ' FOLDER I'm changing into
    .WriteLine "mget *." & strDate    ' Get all files with today's date in it
    .WriteLine "bye"
    .Close
End With

Then later in your script you just call it:

WSHShell.Run "%comspec% /c FTP -n -s:" & strCommandFile & " " & strSite, 0, True

Where strSite is the IP or name of the site you are trying to connect to.

unrealtrip