Sample code for 30+ languages & platforms
Classic ASP

Check FTP Connection and Login Status

See more FTP Examples

Demonstrates the connection-status properties ConnectVerified, LoginVerified, ConnectFailReason, and Greeting.

Background: When Connect fails, these properties separate the possible causes: ConnectVerified shows whether the TCP connection was established at all, LoginVerified whether authentication then succeeded, and ConnectFailReason gives a numeric code pinpointing the failure — far more actionable than a generic error for distinguishing, say, an unreachable host from a bad password. The Greeting captures the server's opening banner, sometimes useful for identifying the server or its policies.

Chilkat Classic ASP Downloads

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

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

ftp.Hostname = "ftp.example.com"
ftp.Username = "myFtpLogin"

'  Normally you would not hard-code the password in source.  You should instead obtain it
'  from an interactive prompt, environment variable, or a secrets vault.
ftp.Password = "myPassword"

success = ftp.Connect()
If (success <> 1) Then
    '  ConnectFailReason gives a numeric code describing why Connect failed.
    Response.Write "<pre>" & Server.HTMLEncode( "Connect failed, reason code: " & ftp.ConnectFailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

'  After a successful connect, these flags report what succeeded.
Response.Write "<pre>" & Server.HTMLEncode( "TCP connection verified: " & ftp.ConnectVerified) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Login verified: " & ftp.LoginVerified) & "</pre>"

'  The Greeting property holds the server's initial greeting banner.
Response.Write "<pre>" & Server.HTMLEncode( "Server greeting: " & ftp.Greeting) & "</pre>"

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


%>
</body>
</html>