ASP to Check if a file exists on an FTP server
am 26.04.2006 23:47:39 von nvanhaasterOk 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
%>
Nightly Reports
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)