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)
