Using the Connect Method

Explicit connection to a server using the Connect method should be used in either of the following situations:

  1. You plan to do multiple file transfers in a single session, or
  2. You wish to generate file listings or do other remote file management activities with an FTP server.

The Connect method has several parameters, all of which are optional:

Connect([ServerName] [,ServerPort] [,UserName] [,Password] [,Timeout] [,Options])

If a given parameter is missing, then the current value of the corresponding property will be used in establishing the connection.

For example:

lResult = FileTransfer1.Connect(strServerName, nServerPort, _
                                strUserName, strPassword, _
                                nTimeout, lOptions)

... is the same as this:

With FileTransfer1
    .ServerName = strServerName
    .ServerPort = nServerPort
    .UserName = strUserName
    .Password = strPassword
    .Timeout = nTimeout
    .Options = lOptions
    lResult = .Connect
End With

Note that there are properties that may affect establishing a connection, but are not available as parameters of the Connect method. Namely ServerType, Secure, KeepAlive (for HTTP), Account (for FTP), and the Proxy-related properties.

In the following examples, properties not explicitly mentioned are assumed to have their default values.

' Connect to a non-secure FTP server,
' using a user-specified timeout
' 
FileTransfer1.ServerType = fileServerFtp
lResult = FileTransfer1.Connect(editServerName.Text, , _
                                editUserNameText, editPasswordText, _
                                editTimeout.Text, lOptions)
If lResult <> 0 Then
    MsgBox "Connection attempt failed"  & vbCrLf & _
          FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If
...

' Connect to a security-enabled FTP server
' that requires TLS authorization,
' and which is listening on port 21,
' with default timeout
' 
FileTransfer1.ServerType = fileServerFtp
FileTransfer1.Secure = True

'
' 21 is not the reserved FTPS port, so we must specify it
'
lResult = FileTransfer1.Connect(editServerName.Text, 21 , _
                                editUserNameText, editPasswordText, , _
                                fileOptionSecureExplicit)
If lResult <> 0 Then
    MsgBox "Connection attempt failed"  & vbCrLf & _
          FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If
...

' Connect to a security-enabled HTTP server
' using standard port assignments,
' persistent connection,
' and default timeout
' 
FileTransfer1.ServerType = fileServerHttp
FileTransfer1.Secure = True
FileTransfer1.KeepAlive = True 
lResult = FileTransfer1.Connect(editServerName.Text)
If lResult <> 0 Then
    MsgBox "Connection attempt failed"  & vbCrLf & _
          FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If
...


Copyright © 2008 Catalyst Development Corporation. All rights reserved.