Hello there ..
I'm using the following the VBS script to retrieve a file from a
remote website. Everything works fine - almost. The problem is that
the file naming convention of the file I'm retrieving is date stamped
with the date and time the file was created. Here's the naming
convention for files in the outgoing account:
CompanyName_MMDDYY_hhmmss.txt (ie
CompanyName_MonthDayYear_HourMinuteSecond.txt)
Example: FordMotor_102403_150100.txt
Since I retrieve files on a daily basis I obviously know the first
half of the file name, but since I don't know exactly when the file is
created I don't know the 2nd half.
I've tried this without success:
RemoteFile = "SomeCompany_" + mm + dd + yy + "_" + ****** + ".txt"
Here's the full script below:
*************************************************
Option Explicit : Dim LocalDir, FTPaddr, UserName, Password, BaseDir
Dim args, fso, ws, InFile, ftp, OutFile, f, TextFile, ofile, oName
FTPaddr = "ftp.SomeCompany.com"
LocalDir = "D:\Inetpub\CompanyName\Import\"
UserName = "XXXXXXXXX"
Password = "XXXXXXXXX"
Set args = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
InFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
Set ftp = fso.OpenTextFile(InFile, 2, True)
OutFile = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
'--Create the target remote file to look for
Dim mm,dd,yy, RemoteFile
mm = Month(now)
dd = Day(now)
yy = Right(Year(now),2)
if mm < 10 then
mm = "0" & mm
end if
if dd < 10 then
dd = "0" & dd
end if
RemoteFile = "SomeCompany_" + mm + dd + yy + "_" + ****** + ".txt"
LocalDir = LocalDir & RemoteFile
' File nameing convention: SomeCompany_MMDDYY_HRMMSC.txt
Download()
ws.Run "%comspec% /c ftp -i -s:" & InFile & " >" & OutFile, 0, True
Cleanup() 'Release objects and exit
'---------Subs----------------------------------------------------
Sub Download()
With ftp
.WriteLine "open " & FTPaddr
.WriteLine UserName
.WriteLine Password
.WriteLine "binary"
.WriteLine "get "
.WriteLine RemoteFile
.WriteLine chr(34) & LocalDir & chr(34)
.WriteLine "close"
.WriteLine "bye"
.Close
End With
End Sub
Sub Cleanup()
On Error Resume Next
fso.DeleteFile InFile, True
fso.DeleteFile OutFile, True
fso.DeleteFile BaseDir, true
Set args = Nothing
Set fso = Nothing
Set ws = ""
Set ftp = ""
WScript.Quit
End Sub
********************************************
Thanks you kind people !!!!!!!!!!!!!!!!!!
Bill