"Phillip Armitage" <> wrote in message
news:...
> I've spent the better part of two days checking out PHP, javascript and
> numerous other language sites trying to find what I figure should be be an
> easy web script page. Essentially what I want is a self calling script
(ASP,
> PHP, whatever) which will do the following:
>
> Let's assume that my script is called FTP.ASP
>
> 1) Display an HTML login form prompting user to enter a user name and
> password. Login button action (either at the button or form level) calls
> ftp.asp again. Ftp server name is hardcoded into the ASP code.
>
> 2) When login is clicked on and page reloads itself, take user name and
> password values and use them to attempt make a connection to an FTP server
> (lots of code out there showing how to do this in PHP. Shame that my
version
> of php isn't supporting the ftp requests). If login/connection is
> unsuccessful, display login form again with a message that previous
attempt
> failed, please try again.
>
> 3) If ftp connection was successful, then username/password combination
must
> be valid. Open URL ftp://username
.
>
> In ASP I've found enough information to accomplish parts 1 and 3. However,
I
> can't seem to find anything about ASP ftp functions which could be used to
> do part 2.
>
> Without having to load third party ftp utilities on my IIS 5 server, any
> suggestions on how I can perform step 2? Link to an ASP (not ASP.NET) page
> explaining built-in ftp functions?
>
> I look forward to your response
Will this help? Watch for word-wrap.
<%@ Language="VBScript" %>
<% Option Explicit
'*
'* Declare Constants
'*
Const cASP = "LoginFTP.asp"
Const cFTP = "LoginFTP.ftp"
Const cLOG = "LoginFTP.log"
Const cDOM = "lmsrf.org" 'mydomain.com"
Const cWSS = "%comspec% /C "
Const c500 = "500 " '= Invalid userid/password"
Const c530 = "530 " '= User ??? cannot log in."
Const cERR = "<b>Invalid Username or Password!</b><br><br>"
'*
'* Declare Globals
'*
Dim strUSR
strUSR = Request.Form("User")
Dim strPWD
strPWD = Request.Form("Pass")
Dim strURL
strURL = "ftp://" & strUSR & ":" & strPWD & "@" & cDOM
'*
'* LoginFTP()
'*
If strUSR <> "" And strPWD <> "" Then
If LoginFTP() Then
Response.Redirect(strURL)
Else
Response.Write(cERR)
End If
End If
Function LoginFTP()
'****
'* Return result of attempted login.
'****
LoginFTP = False
'*
'* Declare Variables
'*
Dim strFTP
strFTP = Server.MapPath(cFTP)
Dim strLOG
strLOG = Server.MapPath(cLOG)
Dim strOTF
strOTF = "open " & cDOM & vbCrLf
strOTF = strOTF & strUSR & vbCrLf
strOTF = strOTF & strPWD & vbCrLf
strOTF = strOTF & "close" & vbCrLf
strOTF = strOTF & "bye" & vbCrLf
Dim strWSS
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objOTF
Dim objWSS
'*
'* Delete ".ftp"
'*
If objFSO.FileExists(strFTP) Then objFSO.DeleteFile(strFTP)
'*
'* Create ".ftp"
'*
Set objOTF = objFSO.OpenTextFile(strFTP,2,true)
objOTF.WriteLine(strOTF)
objOTF.Close()
Set objOTF = Nothing
'*
'* Run ".ftp" to Create ".log"
'*
strWSS = cWSS & " ftp -i -s:" & strFTP & " > " & strLOG
Set objWSS = Server.CreateObject("WScript.Shell")
objWSS.Run strWSS,2,True
Set objWSS = Nothing
'*
If objFSO.FileExists(strFTP) Then objFSO.DeleteFile(strFTP)
'*
'* Read ".log"
'*
Set objOTF = objFSO.OpenTextFile(strLOG,1)
strOTF = objOTF.ReadAll()
objOTF.Close()
Set objOTF = Nothing
'*
Set objFSO = Nothing
'*
'* Return
'*
If InStr(strOTF,c500) > 0 Then Exit Function
If InStr(strOTF,c530) > 0 Then Exit Function
LoginFTP = True
End Function
%>
<html>
<head>
<title><%=cASP%></title>
</head>
<body>
<form action="<%=cASP%>" method="post">
<br><b>Username : </b>
<input type="text" name="User" size="10" maxlength="10">
<br><b>Password : </b>
<input type="text" name="Pass" size="10" maxlength="10">
<br>
<input type="submit" value="Login FTP">
</form>
</body>
</html>