Sample code for 30+ languages & platforms
Classic ASP

Connect to an FTP Server Without Logging In

See more FTP Examples

Demonstrates the Chilkat Ftp2.ConnectOnly method, which establishes the connection (including any proxy and TLS setup) and receives the greeting, but does not send USER or PASS. It takes no arguments; authentication is completed with LoginAfterConnectOnly.

Background: Splitting connect from login gives you a window between the two — to read the greeting, decide which account to use, or set up TLS options that depend on the server — that the all-in-one Connect does not. After ConnectOnly the control connection is open and CheckConnection returns true even though the session is not yet authenticated.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Demonstrates the Ftp2.ConnectOnly method, which establishes the connection (including any proxy
'  and TLS setup) and receives the greeting, but does NOT send USER or PASS.  It takes no
'  arguments.  Authentication is completed separately with LoginAfterConnectOnly.

set ftp = Server.CreateObject("Chilkat.Ftp2")

ftp.Hostname = "ftp.example.com"
ftp.Port = 21

'  Connect without logging in.
success = ftp.ConnectOnly()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Connected (not yet logged in).") & "</pre>"

'  The greeting is now available; credentials can be set based on it, then authenticate.
ftp.Username = "myFtpLogin"
ftp.Password = "myPassword"

success = ftp.LoginAfterConnectOnly()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Logged in.") & "</pre>"

success = ftp.Disconnect()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If


%>
</body>
</html>