SmartFTP FTP Library
IFTPPortPool Interface Reference

Manages a specific range of local ports for Active FTP data connections. More...

import "sfFTPLib.idl";

Public Member Functions

HRESULT NextPort ([out, retval] long *retval)
 Retrieves the next available port from the configured pool.
HRESULT SetPortRange ([in] long minPort, [in] long maxPort)
 Defines the range of local ports to use.

Properties

long MinPort [get]
 Retrieves the lower bound of the allowed port range.
long MaxPort [get]
 Retrieves the upper bound of the allowed port range.

Detailed Description

Manages a specific range of local ports for Active FTP data connections.

This interface is used to control which local client-side ports are used when establishing an Active Mode (PORT/EPRT) data connection.

Why use this? In Active FTP, the client opens a random port and asks the server to connect back to it. Firewalls often block these incoming connections on random ports.

By using this interface, you can restrict the client to use a specific range of ports (e.g., 50000-50100) that you have explicitly allowed in your local firewall or NAT router.

Member Function Documentation

◆ NextPort()

HRESULT IFTPPortPool::NextPort ( [out, retval] long * retval)

Retrieves the next available port from the configured pool.

This method implements a Round-Robin selection strategy:

  1. It returns the current port number and increments the internal counter.
  2. If the counter exceeds MaxPort, it wraps around to MinPort.

This ensures that ports are reused evenly, reducing the chance of "Address Already in Use" errors during rapid file transfers.

Parameters
[out]retvalPointer to a long that receives the next port number to bind.

◆ SetPortRange()

HRESULT IFTPPortPool::SetPortRange ( [in] long minPort,
[in] long maxPort )

Defines the range of local ports to use.

Sets the inclusive boundaries for the port pool. The internal iterator is reset to minPort immediately after calling this method.

Validation:

  • minPort must be less than or equal to maxPort.
  • Ports must be within the valid TCP range (1 - 65535).
  • It is recommended to use ports above 1024 (Ephemeral range) to avoid conflicts with system services.
Parameters
[in]minPortThe lowest allowed port number.
[in]maxPortThe highest allowed port number.

Property Documentation

◆ MaxPort

long IFTPPortPool::MaxPort
getproperty

Retrieves the upper bound of the allowed port range.

This is the inclusive end value of the pool (e.g., 50100).

Parameters
[out]retvalPointer to a long that receives the maximum port number.

◆ MinPort

long IFTPPortPool::MinPort
getproperty

Retrieves the lower bound of the allowed port range.

This is the inclusive start value of the pool (e.g., 50000).

Parameters
[out]retvalPointer to a long that receives the minimum port number.

The documentation for this interface was generated from the following file: