ASP to Check if a file exists on an FTP server

Ok I have a script that is designed to access a FTP site to GET, PUT
and DELETE files. It is initiated by a page where the user enters in a
few variables that get stored in a database for future reporting. All
that aside what I am looking for is a simple way through ASP (vbscript)
to first loginto the FTP server and check if the files are there, then
give a message box back to the USER displaying the different types of
Files found. Here is an example of the message box:
===================
LogHours File : Found
NLHours File : Found
NYHours File : Not Found
HR Data File : Found
"OK" "CANCEL"
====================

The problem I am having is determining what i should be using, should i
be using my FTP script to log into the FTP site or can I use
Scripting.FileSystemobject. From what i know the
Scripting.FileSystemobject is only for local files.

So then comes what commands could i use to check if a file is on an FTP
Site?

Here is my code for the user input page. If you need more details
please let me know

<%
Dim Site
Dim isActive
Dim adoCon
Dim rsSite
Dim strSQL

Dim uname,fromemail,fromname
Dim rsPass
Dim pasSQL
uname = Request.Cookies("cookiename")("value")


Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("/db.mdb")
Set rsSite = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM locations ORDER BY location;"
rsSite.Open strSQL, adoCon

%>

<head>
<style>
TD.view
{
FONT-SIZE: 8pt;
COLOR: black;
LINE-HEIGHT: normal;
FONT-STYLE: normal;
FONT-FAMILY: Arial;
FONT-VARIANT: normal
}
</style>
<SCRIPT language=vbscript>
Function checkDate()
dim result
document.form1.ndate.value = cdate(document.form1.ndate.value)
If Not isDate(document.form1.ndate.value) then
alert("Invalid Date Please Re-Enter")
ElseIf DateDiff("d", document.form1.ndate.value, date()) then
result = msgbox("Date Specified is not the Current Date." & Chr(13)
& "Current Date is: " & date() & Chr(13) & "Proceed?",17,"ALERT :
Date")
End If
If result = 2 then
document.form1.ndate.value = date()
'alert("Changing Date To: " & date())
End If
If mid(document.form1.ndate.value,2,1) = "/" then
document.form1.ndate.value = "0" & document.form1.ndate.value
End If
If mid(document.form1.ndate.value,5,1) = "/" then
document.form1.ndate.value = left(document.form1.ndate.value,3) &
"0" & mid(document.form1.ndate.value,4,6)
End If
End Function

Function nextpage()
Dim site
Dim dates
Dim bhours
Dim dthours
Dim ghours
dates = document.form1.ndate.Value
site = document.form1.site.Value
bhours = document.form1.bhours.Value
ghours = document.form1.ghours.Value
dthours = document.form1.thours.Value
window.location.href "validate.asp?site=" & site & "&dates=" & dates
& "&bhours=" & bhours & "&ghours=" & ghours & "&dthours=" & dthours
End Function
</SCRIPT>
</head>
<body style="font-family: Arial">
<h3>Nightly Reports</h3>
<TABLE BORDER=0 WIDTH=70% CELLSPACING=0 COLSPAN=10>
<FORM name="form1">
<tr><td class=view><b>Date: </td><td class=view><input type=text
name="ndate" size="10" onchange=checkdate()></td></tr>
<tr><td class=view><b>Billable Hours</b></td><td class=view><input
type=text size=10 name=bhours value=0></td></tr>
<tr><td class=view><b>Goal Hours</b></td><td class=view><input
type=text size=10 name=ghours value=0></td></tr>
<tr><td class=view><b>Dialer Training Hours</b></td><td
class=view><input type=text size=10 name=thours value=0></td></tr>
<tr><td class=view><b>Location:</td><td class=view><select
name=site><option SELECTED>--Select Site--</option>
<%
Do While Not rsSite.EOF
If rsSite("isOpen") = "True" Then
response.write "<option value=" & rsSite("OfficeID") & ">" &
rsSite("location") & "</option>"
End If
rsSite.MoveNext
Loop
%>
</select></td></tr>
<tr><td class=view><input type=button name=submit value="<-Update->"
onclick=Nextpage()></td><td class=view><input type=reset name=submit
value=Reset></td>
</form>
</table>
</body>

The FTP Code that Has Been Modified From a webpost other places

'=====================
Function FTP( strCMD )
'=====================
Dim strFile, objTempFldr, objFile, objRegExp
Dim objShell, WSX, ReturnCode, Output, strLog, strErrorLog
Dim objFSO

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

set objTempFldr = objFSO.GetSpecialFolder( 2 )
strFile = objFSO.GetTempName

strFile = objTempFldr & "" & strFile & ".ftp"
if not objFSO.FileExists( strFile ) then objFSO.CreateTextFile( strFile
)
Set objFile = objFSO.OpenTextFile( strFile, 2, True )

objFile.WriteLine( strUser )
objFile.WriteLine( strPass )
If LocalDir <> "" Then objFile.WriteLine( "lcd " & LocalDir )
If RemoteDir <> "" Then objFile.WriteLine( "cd " & RemoteDir )
objFile.WriteLine( Mode )


objFile.WriteLine( strCMD )
objFile.WriteLine( "bye" )
objFile.Close()
Set objShell = Server.CreateObject("WScript.Shell")


set WSX = objShell.Exec( COMMAND_FTP & strFile & " " & strHost )
set ReturnCode = WSX.StdErr
set Output = WSX.stdOut
strErrorLog = objTempFldr.Path & "ftpErrors.txt"
strLog = objTempFldr.Path & "ftpLog.txt"

Set objFile = objFSO.OpenTextFile( strErrorLog, 2, True )
objFile.Write( ReturnCode.ReadAll() )
objFile.Close()

Set objFile = objFSO.OpenTextFile( strLog, 2, True )
objFile.Write( Output.ReadAll() )
objFile.Close()

'objFSO.DeleteFile strFile, True
set objFSO = nothing

Set objRegExp = New RegExp
objRegExp.IgnoreCase = True

objRegExp.Pattern = "not connected|invalid command|error"

If (objRegExp.Test( Output.ReadAll ) = True ) or (objRegExp.Test(
ReturnCode.ReadAll ) ) Then
FTP = False
Else
FTP = True
End If
Set objRegExp = nothing

End Function
'==================================
'==================================

FTP(strCommands)
nvanhaaster [ Mi, 26 April 2006 23:47 ] [ ID #1290406 ]

Re: ASP to Check if a file exists on an FTP server

Just to Add the file names are easy such as
NLFiles.TXT
NYFiles.TXT
LGFile.csv
HRFile.csv
nvanhaaster [ Do, 27 April 2006 00:00 ] [ ID #1290407 ]

Re: ASP to Check if a file exists on an FTP server

<nvanhaaster [at] caitele.com> wrote in message
news:1146088059.264131.242480 [at] i39g2000cwa.googlegroups.com.. .
> Ok I have a script that is designed to access a FTP site to GET, PUT
> and DELETE files. It is initiated by a page where the user enters in a
> few variables that get stored in a database for future reporting. All
> that aside what I am looking for is a simple way through ASP (vbscript)
> to first loginto the FTP server and check if the files are there, then
> give a message box back to the USER displaying the different types of
> Files found. Here is an example of the message box:
> ===================
> LogHours File : Found
> NLHours File : Found
> NYHours File : Not Found
> HR Data File : Found
> "OK" "CANCEL"
> ====================
>
> The problem I am having is determining what i should be using, should i
> be using my FTP script to log into the FTP site or can I use
> Scripting.FileSystemobject. From what i know the
> Scripting.FileSystemobject is only for local files.
>
> So then comes what commands could i use to check if a file is on an FTP
> Site?

[snip]

One approach is to use ftp to download the contents of the directory
and examine it for the files of interest.

Try the following after changing the values of:
cDOM, cUSR, cPWD, and cDIR.

Also, the "ftp_dir." filename prefix values could be changed if you want.


Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "ftp_dir.vbs"
Const cFTP = "ftp_dir.ftp"
Const cLOG = "ftp_dir.log"
Const cWSS = "%comspec% /C ftp -i -s:"
'*
Const cDOM = "your_domain.com"
Const cUSR = "your_username"
Const cPWD = "your_password"
Const cDIR = "your_subdirectory_if_applicable"
'*
'* Declare Variables
'*
Dim arrFIL(3)
arrFIL(0) = "NLFiles.TXT"
arrFIL(1) = "NYFiles.TXT"
arrFIL(2) = "LGFile.csv"
arrFIL(3) = "HRFile.csv"
Dim intFIL
Dim strFIL
Dim strFTP
strFTP = "open %dom|%usr|%pwd|hash|ascii|cd %dir|dir|close|bye"
strFTP = Replace(strFTP,"%dom",cDOM)
strFTP = Replace(strFTP,"%usr",cUSR)
strFTP = Replace(strFTP,"%pwd",cPWD)
strFTP = Replace(strFTP,"%dir",cDIR)
strFTP = Replace(strFTP,"|",vbCrLf)
Dim strLOG
Dim strMSG
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
Dim objWSS
'*
'* FTP File
'*
Set objOTF = objFSO.OpenTextFile(cFTP,2,true)
objOTF.WriteLine(strFTP)
Set objOTF = Nothing
'*
'* FTP Exec
'*
Set objWSS = CreateObject("WScript.Shell")
objWSS.Run cWSS & cFTP & " >> " & cLOG,2,True
Set objWSS = Nothing
'*
'* LOG File
'*
Set objOTF = objFSO.OpenTextFile(cLOG,1)
strLOG = objOTF.ReadAll
Set objOTF = Nothing
'*
'* Destroy Objects
'*
objFSO.DeleteFile(cFTP,True)
Set objFSO = Nothing
'*
'* Finish
'*
For intFIL = 0 To UBound(arrFIL)
strFIL = arrFIL(intFIL)
strMSG = strMSG & vbCrLf & strFIL & " : "
If InStr(strLOG,strFIL) > 0 Then
strMSG = strMSG & "Found"
Else
strMSG = strMSG & "Not Found"
End If
Next
MsgBox strMSG,vbOKCancel,cVBS



If case-sensitivity of filenames is an issue then just change:
If InStr(strLOG,strFIL) > 0 Then
to
If InStr(LCase(strLOG),LCase(strFIL)) > 0 Then
McKirahan [ Do, 27 April 2006 04:33 ] [ ID #1292100 ]
Webserver » microsoft.public.inetserver.asp.db » ASP to Check if a file exists on an FTP server

Vorheriges Thema: i wanna help in deling sql server 2000
Nächstes Thema: Type mismatch: 'rst' and cant get value out from database