The File Transfer Server class provides an interface for implementing an embedded, lightweight server that can be used to exchange files with a client using the standard File Transfer Protocol. The server can accept connections from any third-party application or a program developed using SocketTools. The application specifies an initial server configuration by setting the relevant properties and can implement event handlers to monitor the activities of the clients that have connected to the server. The class automatically handles the standard FTP commands and requires minimal coding on the part of the application that is hosting the control. However, the application may also use event mechanism to filter specific commands or to extend the protocol by providing custom implementations of existing commands or add entirely new commands.
An important consideration when using this class is that events are raised in the context of the thread that manages the client session. The .NET Framework does not allow one thread to modify a control that was created in the main user interface thread, which means that you cannot update user interface controls directly from within the event handlers. If you want to change any property values or call methods in a control, you need to create a delegate and marshal the call to the user interface thread to using the control's Invoke method.
Initialize
Initialize an instance of the class, loading the networking library and
validating the development license. This method must be called before
any properties are changed or any other methods in this class are called
by the application.
Start
This method starts the server, creating the background thread and listening for
incoming client connections on the specified port number. You can
specify the local address, port number, backlog queue size and the
maximum number of clients that can establish a connection with the
server.
Restart
This method will terminate all active client connections, close the listening
socket and re-create a new listening socket bound to the same address and port
number.
Suspend
This method instructs the server to temporarily suspend accepting new client
connections. Existing connections are unaffected, and any incoming client
connections are rejected until the server is resumed. It is not
recommended that you leave a server in a suspended state for an extended
period of time.
Resume
This function instructs the server to resume accepting client connections after
it was suspended. Any pending client connections are accepted after the server
has resumed normal operation.
Throttle
This method is used to control the maximum number of clients that may connect
to the server, the maximum number of clients that can connect from a single IP
address and the rate at which the server will accept client connections. By
default, there are no limits on the number of active client sessions and
connections are accepted immediately. This method can be useful in preventing
denial-of-service attacks where the the attacker attempts to flood the server
with connection attempts.
Stop
This method will terminate all active client connections, close the listening
socket and terminate the background thread that manages the server. Any incoming
client connections will be refused, and all resources allocated for the server
will be released.
Uninitialize
Unload the networking library and release any resources that have been
allocated for the class instance. This method is automatically invoked
when the class instance is disposed or goes out of scope.
The application is informed of all client activity through event notifications. These events will tell your program when a client has connected, issued a command, uploaded or downloaded a file or disconnects from the server. Through the event mechanism it's also possible to implement your own custom commands.
OnConnect
This event occurs when the client first establishes a connection with
the server. At this point, the client is in an unauthenticated state and
may only issue a limited subset of commands before it submits user
credentials for authentication. This event provides your application
with the unique client ID that identifies the session and the remote IP
address that the client has connected from.
OnAuthenticate
This event occurs when the client has submitted user credentials for
authentication. The class supports several mechanisms for user
authentication, including automatic local user authentication, the
creation of one or more virtual users or custom authentication by
implementing an event handler for this event. It is not necessary to
implement a handler for this event if you choose to create virtual user
accounts for your server instance because the server will automatically
handle authentication for those users.
OnCommand
This event occurs for each command sent by the client, prior to the
command being processed by the server. This event can be used by your
application to monitor the commands that are being issued, or may create
an event handler that filters certain commands or implements support for
custom commands by processing the command in your own code.
OnResult
This event occurs after each command has been processed by the server.
This event can be used by your application to monitor those commands
which were successful and those which failed. For example, your
application could use this event to track the actions of a client and
terminate the session if the client is issuing a large number of
commands that fail.
OnDownload
This notification event occurs after a file has been successfully
downloaded by a client. It can be used for logging and monitoring
purposes or to update your user interface with relevant information
about the current client activity.
OnUpload
This notification event occurs after a file has been successfully
uploaded by a client.
OnDisconnect
This event occurs after a client has disconnected from the server and
the thread that manages the client session has released all of the
resources allocated for that client.
Several properties are provided to return information about the local host, including its fully qualified domain name and the IP addresses that are configured on the system.
ServerName
Return the fully qualified domain name of the local host, if it has been
configured. If the system has not been configured with a domain name,
then the machine name is returned instead.
ExternalAddress
Return the IP address assigned to the router that connects the local
host to the Internet. This is typically used by an application executing
on a system in a local network that uses a router which performs Network
Address Translation (NAT).
AdapterAddress
This property array returns the IP addresses that are associated with
the local network or remote dial-up network adapters configured on the
system. The AdapterCount property can be used to determine the number of
adapters that are available.