FtpCreateQueue Function  
 
HQUEUE WINAPI FtpCreateQueue(
  UINT nMaxFiles,  
  UINT nTimeout,  
  DWORD dwOptions  
);

The FtpCreateQueue function creates new file transfer queue.

Parameters

nMaxFiles
An unsigned integer which specifies the maximum number of files which can be added to the queue. The constant INFINITE can be used to specify that there is no fixed limit to the number of files in the queue.
nTimeout
An unsigned integer which specifies the default timeout for all queued file transfers. If this value is zero, a reasonable default timeout period will be used. This timeout period is used when a file is added to the queue without providing a timeout period for that specific file transfer. If a timeout period is specified for a particular file, it will override this value.
dwOptions
An unsigned integer value which specifies one or more default options for all queued files. This parameter is constructed by using a bitwise operator and can be any of the options used with the FtpConnect function. If transfer options are specified for a particular file, it will override this value. The most common options are:
Value Description
FTP_OPTION_DEFAULT Default options should be used for queued file transfers. This is the same as specifying that all file transfers should use passive mode when establishing a data connection with the server. It is recommended most applications use passive mode to prevent potential compatibility issues with certain types of firewalls and routers which use Network Address Translation (NAT).
FTP_OPTION_PASSIVE This option specifies queued transfers should attempt to establish the data connection with the server. If the local system is behind a firewall or a NAT router, the server may not be able to establish a data connection back to the client and the transfer will fail. This option forces the client to establish an outbound data connection with the server. It is recommended that applications use passive mode whenever possible.
FTP_OPTION_FIREWALL This option specifies queued transfers should always use the host IP address to establish the data connection with the server, not the address returned by the server in response to the PASV command. This option may be necessary if the server is behind a router that performs Network Address Translation (NAT) and it returns an unreachable IP address for the data connection. If this option is specified, it will also enable passive mode data transfers.
FTP_OPTION_SECURE This option specifies queued file transfers should attempt to establish a secure connection with the server by default. This option is the same as specifying FTP_OPTION_SECURE_IMPLICIT which immediately performs the TLS protocol negotiation when the connection is established.
FTP_OPTION_SECURE_IMPLICIT This option specifies queued file transfers should attempt to immediately establish secure TLS connection with the server by default. This option is typically used when connecting to a server on port 990, which is the default port number used for FTPS.
FTP_OPTION_SECURE_EXPLICIT This option specifies queued file transfers should establish a standard connection to the server and then use the AUTH command to negotiate an explicit secure connection. This option is typically used when connecting to the server on ports other than 990.
FTP_OPTION_SECURE_SHELL This option specifies queued file transfers should use the Secure Shell (SSH) protocol to establish the connection by default. This option will automatically be selected if the connection is established using port 22, the default port for SSH.

Return Value

If the function succeeds, the return value is a handle to the queue which can be used with subsequent function calls. If the function fails, the return value is INVALID_QUEUE. To get extended error information, call FtpGetLastError.

Remarks

If the nMaxFiles parameter is INFINITE, memory will be dynamically allocated on the process heap with no limit to the number of files which can be queued. If there is a logic error which causes the application to recursively add files to the queue, or repeatedly queue the same file, this can result in virtual memory being exhausted for the process. You can avoid this by specifying a reasonable maximum queue size, which will cause the FtpAddQueuedFile function to fail if that limit is exceeded.

The memory allocated for the queue will be released when the FtpDeleteQueue function is called.

Example

// Create a new queue
HQUEUE hQueue = FtpCreateQueue(INFINITE, FTP_TIMEOUT, FTP_OPTION_DEFAULT);

if (hQueue == INVALID_QUEUE)
    return;

// Add a file to the queue
DWORD dwFileId = FtpAddQueuedFile(
                     hQueue,
                     lpszLocalFile,
                     lpszRemoteFile,
                     FTP_OPTION_DEFAULT,
                     FILE_TYPE_AUTO,
                     FTP_TIMEOUT);

// Display information about the queued file
if (dwFileId != 0)
{
    FTPQUEUEDFILE queuedFile;

    if (FtpGetQueuedFile(hQueue, dwFileId, &queuedFile))
    {
        switch (queuedFile.dwMode)
        {
        case FTP_QUEUE_DOWNLOAD:
               _tprintf(_T("%u: Download \"%s\" to \"%s\"\n"),
                        dwFileId,
                        queuedFile.szRemoteFile,
                        queuedFile.szLocalFile);
                break;

        case FTP_QUEUE_UPLOAD:
               _tprintf(_T("%u: Upload \"%s\" to \"%s\"\n"),
                        dwFileId,
                        queuedFile.szLocalFile,
                        queuedFile.szRemoteFile);
                break;
        }
    }
}

// Start the queued file transfers and wait for it to complete
if (FtpStartQueue(hQueue, FTP_QUEUE_ALL, 0, NULL, 0))
{
    FtpWaitForQueue(hQueue, INFINITE, &dwElapsed, &dwError);
    FtpStopQueue(hQueue);
}

// Remove all files from the queue
FtpDeleteQueue(hQueue);

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csftpv12.lib

See Also