| |
| DWORD AddFile( |
| |
DWORD dwQueueMode, |
|
| |
LPCTSTR lpszLocalFile, |
|
| |
LPCTSTR lpszRemoteFile, |
|
| |
DWORD dwOptions, |
|
| |
UINT nFileType, |
|
| |
UINT nTimeout |
|
| ); |
| DWORD AddFile( |
| |
DWORD dwQueueMode, |
|
| |
LPCTSTR lpszHostName, |
|
| |
UINT nHostPort, |
|
| |
LPCTSTR lpszUserName, |
|
| |
LPCTSTR lpszPassword, |
|
| |
LPCTSTR lpszLocalFile, |
|
| |
LPCTSTR lpszRemoteFile, |
|
| |
DWORD dwOptions, |
|
| |
UINT nFileType, |
|
| |
UINT nTimeout |
|
| ); |
The AddFile method adds a new file to the queue
with additional transfer options.
Parameters
- dwQueueMode
- An integer value which specifies if the file should be
downloaded from the server or uploaded to the server. This parameter
must be one of the following options and cannot have a value of
zero.
| Constant |
Description |
| FTP_QUEUE_DOWNLOAD |
The file should be queued for downloading from the server to
the local system. |
| FTP_QUEUE_UPLOAD |
The file should be queued for uploading from the local
system to the server. |
- lpszHostName
- The name of the server to establish a connection
with. This may be a fully-qualified domain name or an IP address.
If this parameter is NULL or points to an empty string, the
lpszRemoteFile parameter must specify a complete URL which
identifies the server as well as the path to the remote file.
- nHostPort
- The port number which should be used when establishing the
connection. A value of zero specifies that the default port number
should be used. For standard connections, the default port number
is 21. For secure connections, the default port number is 990. If
this parameter is zero and a URL is specified with the
lpszRemoteFile parameter, the port number included in the
URL will be used as the default value.
- lpszUserName
- A null-terminated string which specifies the user name
to be used to authenticate the connection. If this
parameter is NULL or an empty string, then the login is considered
to be anonymous. Note that anonymous logins are not supported for
secure connections using the SSH protocol.
- lpszPassword
- A null-terminated string which specifies the password
to be used to authenticate the current client session. This
parameter may be NULL or an empty string if no password is required
for the specified user, or if no username has been specified.
- lpszLocalFile
- A null-terminated string which specifies the name
of the local file to be queued for transfer. This parameter cannot
be NULL or point to an empty string. If the file is being queued for
an upload, the file must exist on the local system or the method
will fail. If the file is being downloaded, it will be created or
replaced on the local system.
- lpszRemoteFile
- A null-terminated string which specifies the name
of the file on the server. If the file is being downloaded, the file
must exist on the server or the transfer will fail. If the file is
being uploaded, the file will be created or replaced on the server.
This parameter may specify a complete URL. Note that any values you
specify as arguments to this method will override the values
specified in the URL. If you want to use a URL as the remote file
name, the lpszHostName parameter should be NULL and the
nHostPort
parameter should be zero.
- dwOptions
- An unsigned integer value which specifies one or more options. This
parameter is constructed by using a bitwise operator and can be any
of the options used with the FtpClient::Connect method.
If this value is zero, the default options for the queue will be
used. The most common options are:
| Value |
Description |
| FTP_OPTION_PASSIVE |
This option specifies the file transfer 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 the file transfer 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 the file transfer 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 the file transfer 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 the file transfer 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 the file transfer 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. |
- nFileType
- An integer value which specifies the type of file being
transferred. It can be one of the following values:
| Value |
Description |
| FILE_TYPE_AUTO |
The file type should be automatically determined based on
the file name extension. If the file extension is unknown, the
file type should be determined based on the contents of the
file. The library has an internal list of common text file
extensions, and additional file extensions can be registered
using the RegisterFileType method. |
| FILE_TYPE_ASCII |
The file is a text file using the ASCII character set. For
those servers which mark the end of a line with characters
other than a carriage return and linefeed, it will be converted
to the native client format. This is the file type used for
directory listings. |
| FILE_TYPE_EBCDIC |
The file is a text file using the EBCDIC character set.
Local files will be converted to EBCDIC when sent to the
server. Remote files will be converted to the native ASCII
character set when retrieved from the server. Not all servers
support this file type. It is recommended that you only specify
this type if you know that it is required by the server to
transfer data correctly. |
| FILE_TYPE_IMAGE |
The file is a binary file and no data conversion of any type
is performed on the file. This is the default file type for most
data files and executable programs. If the type of file cannot be
automatically determined, it will always be considered a binary
file. If this file type is specified when uploading or
downloading text files, the native end-of-line character
sequences will be preserved. |
| FILE_TYPE_LOCAL |
The file is a binary file that uses the local byte size for
the server platform. On most servers, this file type is
considered to be the same as FILE_TYPE_IMAGE. Not all servers
support this file type. It is recommended that you only specify
this type if you know that it is required by the server to
transfer data correctly. |
- nTimeout
- The number of seconds to wait for a response
from the server before failing the file transfer. If this value is
zero, the default timeout period for the queue will be used.
- lpvReserved
- A reserved parameter which should always be NULL.
Return Value
If the method succeeds, the return value is a unique identifier
which corresponds to the queued file. If the method fails, the return
value is zero. To get extended error information, call GetLastError.
Remarks
This method will add a file to the current transfer queue. If
successful, the value returned is a unique integer which identifies
that file in the queue. To obtain information about the queued file,
you can call the GetFile method and provide this return value
as the dwFileId parameter. To remove a file from the queue,
use the RemoveFile method.
Files can only be added to the queue when in an idle or
paused state. If you attempt to add a file to the queue while the
queue manager is transferring files, the method will fail. To
determine the current state of the queue, call the GetStatus
method
There are no fixed limits to the number of files which can be
queued for transfer. To release the memory allocated for the queue,
call the Clear method. To determine the current status of the
queue, including how many file transfers have been queued and how
many are pending completion, call the GetStatus method.
If the local file path includes environment variables enclosed in
percentage (%) symbols, those values will be expanded based on the
environment variables defined for the current user using the
ExpandEnvironmentStrings function in the Windows API.
Note that environment variable names are not case-sensitive.
This method will not immediately begin the process of uploading
or downloading the file. It will only add the transfer request to the
current queue. The file transfers are managed by a background worker
thread which is created when the Start method is called.
Example
CFtpQueue pQueue = new CFtpQueue();
if (!pQueue->IsInitialized())
return;
DWORD dwFileId = pQueue->AddFile(
FTP_QUEUE_DOWNLOAD,
lpszHostName,
FTP_PORT_DEFAULT,
lpszUserName,
lpszPassword,
lpszLocalFile,
lpszRemoteFile);
if (dwFileId != 0)
{
FTPQUEUEDFILE queuedFile;
if (pQueue->GetFile(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;
}
}
}
if (pQueue->Start())
{
pQueue->Wait(INFINITE);
pQueue->Stop();
}
delete pQueue;
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
Unicode: Implemented as Unicode and ANSI versions
See Also
|
|