Connect Method  
 

Establish a connection with the specified FTP or HTTP server.

Syntax

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

Parameters

ServerName
An optional string value which specifies the host name or IP address of the server.
ServerPort
An optional integer value which specifies the server port number.
UserName
An optional string value which specifies the username.
Password
An optional string value which specifies the password.
Timeout
An optional integer value which specifies the timeout period in seconds.
Options
An optional integer value which specifies one or more options.
Value Constant Description
1 fileOptionNoCache This instructs an HTTP server to not return a cached copy of the resource. When connected to an HTTP 1.0 or earlier server, this directive may be ignored.
4096 fileOptionSecureImplicit This option specifies that the client should immediately negotiate for a secure session upon establishing a connection with the server. This is the default method for connecting to a secure HTTP server and may also be used with FTP servers that accept secure connections on port 990.
8192 fileOptionSecureExplicit This option specifies that the client should use the AUTH server command to tell an FTP server that it wishes to explicitly negotiate a secure connection. This requires that the server support the AUTH TLS or AUTH SSL commands. Some servers may not require this option, and some may require the option only if a port other than 990 is specified. If this option is specified, the Secure property will automatically be set to True.
16384 fileOptionSecureShell This option specifies that the client should use the Secure Shell (SSH) protocol to establish the connection. This option will automatically be selected if the connection is established using port 22, the default port for SSH, and is only required if the server is configured to use a non-standard port number.

Return Value

A value of zero is returned if the method succeeds. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Remarks

The Connect method is used to establish a connection with the specified server. This is the first method that must be called prior to the application transferring files or issuing FTP commands. If the Connect method is called when a connection already exists, the current connection will be closed.

It is permissible to specify a complete URL as the first argument to the method and the connection will be established with the server using specified protocol. Passing a complete URL to the Connect method has the same effect as setting the URL property and then calling the method with no arguments.

Secure connections cannot be established using the freeware version of this component, they are only supported with the commercial version of SocketTools.

Additional properties that affect the operation of the Connect method are:

  • KeepAlive Property (HTTP)
  • ProtocolVersion Property (HTTP)
  • ProxyPassword Property
  • ProxyPort Property
  • ProxyServer Property
  • ProxyType Property
  • ProxyUser Property
  • Secure Property
  • ServerType Property
  • URL Property

If the ServerType property has the value fileServerUndefined, then the Connect method will try to infer the server type from the value of the ServerPort property. If the server type cannot be automatically determined, an error will be returned and the server type must be explicitly specified.

This method will return a value of zero if the action was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Example

Example 1:

nError = FileTransfer1.Connect("www.bigcorp.com", 80)
If nError > 0 Then
    MsgBox FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If

Example 2:

nError = FileTransfer1.Connect("http://wwww.bigcorp.com")
If nError > 0 Then
    MsgBox FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If

See Also

KeepAlive Property, Secure Property, ServerType Property, ServerName Property, ServerPort Property, UserName Property, Password Property, Timeout Property, URL Property