FTP Login verification

Discussion in 'ASP General' started by Phillip Armitage, Mar 1, 2005.

  1. 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
    Phillip Armitage, Mar 1, 2005
    #1
    1. Advertising

  2. Phillip Armitage

    McKirahan Guest

    "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> &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>
    McKirahan, Mar 1, 2005
    #2
    1. Advertising

  3. Phillip Armitage

    McKirahan Guest

    {snip]

    Make that:

    Const cDOM = "ftp.mydomain.com"
    McKirahan, Mar 1, 2005
    #3
  4. 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.
    Phillip Armitage, Mar 2, 2005
    #4
  5. Phillip Armitage

    McKirahan Guest

    "Phillip Armitage" <> wrote in message
    news:...
    >
    > 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".
    McKirahan, Mar 2, 2005
    #5
  6. Phillip Armitage

    McKirahan Guest

    [snip]

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

    ftp://username:

    from my script. Should this be browser-based?

    Also, I don't know if it's supported under Win XP SP2.
    McKirahan, Mar 2, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,579
    iksrazal
    Apr 25, 2004
  2. Replies:
    3
    Views:
    5,621
  3. Nico Grubert
    Replies:
    0
    Views:
    637
    Nico Grubert
    Nov 24, 2005
  4. Nico Grubert
    Replies:
    0
    Views:
    443
    Nico Grubert
    Nov 25, 2005
  5. D. Buck
    Replies:
    2
    Views:
    477
    D. Buck
    Jun 29, 2004
Loading...

Share This Page