The URL property returns the current Uniform Resource
Locator string which is used by the control to access a resource on
the server. URLs have a specific format which provides information
about the remote host, port, resource, as well as optional
information such as a username and password for authentication:
ftp://[username : [password] @]
remotehost [:remoteport] / [path/...] filename
[;type=id]
http://[username : [password] @]
remotehost [:remoteport] / resource [?
parameters]
The first part of the URL is the scheme and in this case will
always be "ftp", "http", "ftps" or "https" if a secure connection
is being used. If a username and password is required for
authentication, then this will be included in the URL before the
name of the remote host. Next, there is the name of the remote host
to connect to, optionally followed by a port number. If no port
number is given, then the default port for the protocol will be
used. This is followed by the resource, which is usually a path to
a file or script on the server. Parameters to the resource may also
be specified, which are typically used as arguments to a script
that is executed on the server.
Here are some common examples of URLs used to access resources
on an file server:
ftp://www.bigcorp.com/pub/financial/jan2004.xls
In this example, the remote host is www.bigcorp.com, the path is
"pub/financial" and the file name is "jan2004.xls". The default
port will be used to access the file, and no username and password
is provided for authentication so this file must be publically
available to anonymous users.
ftps://executive:secret@www.bigcorp.com/corporate/projections/sales2004.xls
In this example, the remote host is www.bigcorp.com and, the path
is "corporate/projections" and the file name is "sales2004.xls".
Because the protocol is ftps, a secure connection on port 990 will
be established. The user name "executive" and password "secret"
will be used to authenticate the session.
http://www.bigcorp.com/products/index.html
In this example, the remote host is www.bigcorp.com and the
resource is /products/index.html. The default port will be used to
access the resource, and no username and password is provided for
authentication.
https://www.bigcorp.com/order/confirm.asp
In this example, the remote host is www.bigcorp.com and the
resource is the script /order/confirm.asp. Because the protocol is
https, a secure connection on port 443 will be established.
When setting the URL property, the control will parse the
string and automatically update the ServerName,
ServerPort, UserName, Password and
Resource properties according to the values specified in the
URL. This enables an application to simply provide the URL and then
call the Connect method to establish the connection.
Note that if this property is assigned a value which cannot be
parsed, the control will throw an error that indicates that the
property value is invalid. In a language like Visual Basic it is
important that you implement an error handler, particularly if you
are assigning a value to the property based on user input. If the
user enters an invalid URL and there is no error handler, it could
result in an exception which terminates the application.
' Setup error handling since the control will throw an error
' if an invalid URL is specified
On Error Resume Next: Err.Clear
FileTransfer1.URL = Text1.Text
' Check the Err object to see if an error has occurred, and
' if so, let the user know that the URL is invalid
If Err.Number <> 0 Then
MsgBox "The specified URL is invalid", vbExclamation
Text1.SetFocus
Exit Sub
End If
' Reset error handling and connect to the server using the
' default property values that were updated when the URL
' property was set (ie: ServerName, ServerPort, Resource, etc.)
On Error GoTo 0
nError = FileTransfer1.Connect()
If nError <> 0 Then
MsgBox FileTransfer1.LastErrorString, vbExclamation
Exit Sub
End If
' Download the resource and store it in the specified file
nError = FileTransfer1.GetFile(strLocalFile)