|
Explicit connection to a server using the Connect method
should be used in either of the following situations:
- You plan to do multiple file transfers in a single session,
or
- 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.
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
...
FileTransfer1.ServerType = fileServerFtp
FileTransfer1.Secure = True
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
...
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
...
|