| |
| DWORD AddFile( |
| |
DWORD dwQueueMode, |
|
| |
LPCTSTR lpszLocalFile, |
|
| |
LPCTSTR lpszRemoteFile, |
|
| |
DWORD dwOptions, |
|
| |
UINT nTimeout |
|
| ); |
| DWORD AddFile( |
| |
DWORD dwQueueMode, |
|
| |
LPCTSTR lpszHostName, |
|
| |
UINT nHostPort, |
|
| |
UINT nAuthType, |
|
| |
LPCTSTR lpszUserName, |
|
| |
LPCTSTR lpszPassword, |
|
| |
LPCTSTR lpszLocalFile, |
|
| |
LPCTSTR lpszRemoteFile, |
|
| |
DWORD dwOptions, |
|
| |
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 |
| HTTP_QUEUE_DOWNLOAD |
The file should be queued for downloading from the server to
the local system. |
| HTTP_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.
- nAuthType
- An unsigned integer value which specifies the method to be used
when authenticating the client. The following values are supported:
| Value |
Description |
| HTTP_AUTH_NONE |
No client authentication should
be performed. The lpszUserName and lpszPassword
parameters are ignored and current authentication settings
are cleared. |
| HTTP_AUTH_BASIC |
The Basic authentication
scheme should be used. This option is supported by all servers that
support at least version 1.0 of the protocol. The user
credentials are not encrypted and Basic authentication should
not be used over standard (non-secure) connections. Most web
services which use Basic authentication require the connection
to be secure. |
| HTTP_AUTH_BEARER |
The Bearer authentication
scheme should be used. This authentication method does not require a
user name and the lpszPassword parameter must specify the
OAuth 2.0 bearer token issued by the service provider. If the
access token has expired, the request will fail with an
authorization error. |
- 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, no client credentials are provided. If
the authentication type is HTTP_AUTH_BEARER, this parameter is
ignored.
- 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. If the
authentication type is HTTP_AUTH_BEARER, this value must be the
bearer token issued by the service provider.
- 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 HttpClient::Connect method.
If this value is zero, the default options for the queue will be
used. The most common options are:
| Value |
Description |
| HTTP_OPTION_DEFAULT |
Default options should be used for the queued transfer.
All standard headers will be included with the request and
redirected resources will return an error, allowing the
application to determine if it should request the resource from
the new location or inform the user the resource location has
changed. |
| HTTP_OPTION_REDIRECT |
This option specifies the client should automatically
handle resource redirection. If the server indicates that the
requested resource has moved to a new location, the client will
close the current connection and request the resource from the
new location. Note that it is possible that the redirected
resource will be located on a different server. |
| HTTP_OPTION_PROXY |
This option specifies the client should use the
default proxy configuration for the local system. If the system
is configured to use a proxy server, then the connection will
be automatically established through that proxy; otherwise, a
direct connection to the server is established. The local proxy
configuration can be changed in the system settings or control
panel. |
| HTTP_OPTION_HTTP2 |
This option specifies the client should attempt a HTTP/2
connection with the server. If a connection cannot be established
using HTTP/2 the client will attempt to connect using an earlier
version of the protocol. |
| HTTP_OPTION_SECURE |
This option specifies the client should attempt to
establish a secure connection with the server. Note that the
server must support secure connections using the TLS protocol.
The client will default to using TLS 1.2 or later for secure
connections. |
- 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
CHttpQueue pQueue = new CHttpQueue();
if (!pQueue->IsInitialized())
return;
DWORD dwFileId = pQueue->AddFile(
HTTP_QUEUE_DOWNLOAD,
lpszHostName,
HTTP_PORT_DEFAULT,
lpszUserName,
lpszPassword,
lpszLocalFile,
lpszRemoteFile);
if (dwFileId != 0)
{
HTTPQUEUEDFILE queuedFile;
if (pQueue->GetFile(dwFileId, &queuedFile))
{
switch (queuedFile.dwMode)
{
case HTTP_QUEUE_DOWNLOAD:
_tprintf(_T("%u: Download \"%s\" to \"%s\"\n"),
dwFileId,
queuedFile.szRemoteFile,
queuedFile.szLocalFile);
break;
case HTTP_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: cshtpv12.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
|
|