FTP Login verification

  • Thread starter Phillip Armitage
  • Start date
P

Phillip Armitage

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:p[email protected].

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
 
M

McKirahan

Phillip Armitage said:
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:p[email protected].

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> &nbsp;
<input type="text" name="User" size="10" maxlength="10">
<br><b>Password : </b> &nbsp;
<input type="text" name="Pass" size="10" maxlength="10">
<br>
<input type="submit" value="Login FTP">
</form>
</body>
</html>
 
P

Phillip Armitage

So close....

Going through your code, testing it in my environment, I've come to
understand that the way you test if the ftp connection is good is by
attempting to open a file on the FTP server. I presume that you believe the
web server running this app to also be the same server running the FTP
server. Sorry, not the case. The ftp server is running on another box and is
not IIS based.

Any idea if there is something along the lines of a
"CreateObject(FTP.Connection)" that comes as part of either VBScript or IIS?

Thanks for the code. I'll keep it around, just in case I move my FTP server
into IIS.
 
M

McKirahan

Phillip Armitage said:
So close....

Going through your code, testing it in my environment, I've come to
understand that the way you test if the ftp connection is good is by
attempting to open a file on the FTP server. I presume that you believe the
web server running this app to also be the same server running the FTP
server. Sorry, not the case. The ftp server is running on another box and is
not IIS based.

Any idea if there is something along the lines of a
"CreateObject(FTP.Connection)" that comes as part of either VBScript or IIS?

Thanks for the code. I'll keep it around, just in case I move my FTP server
into IIS.


The script isn't "attempting to open a file on the FTP server"; its
attempting to make a connection to the FTP server. The results are placed
in a log file which is examined to see if it failed. If it didn't then it
invokes Response.Redirect.

"I presume that you believe the web server running this app to also be the
same server running the FTP server." -- I do not. "cDOM" identifies the FTP
server both for testing the connection and redirecting. The FTP server does
not have to be "IIS Based".
 
M

McKirahan

[snip]

I wasn't able to get the following to work:

ftp://username:p[email protected]

from my script. Should this be browser-based?

Also, I don't know if it's supported under Win XP SP2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top