| |
| INT WINAPI FtpGetFilePathUrl( |
| |
HCLIENT hClient, |
|
| |
LPCTSTR lpszFilePath, |
|
| |
LPTSTR lpszFileUrl, |
|
| |
INT nMaxLength |
|
| ); |
The FtpGetFilePathUrl function returns a normalized URL for
the specified file on the server.
Parameters
- hClient
- Handle to the client session.
- lpszFilePath
- A null-terminated string which specifies the file path on the
server. The path may be absolute or relative, and the path does not
have to exist on the server. This parameter cannot be NULL.
- lpszFileUrl
- A null-terminated string buffer that will contain the URL for the
specified file. If this parameter is NULL, nothing will be copied
but the function will return the length of the URL, not including
the terminating null character.
- nMaxLength
- An integer value which specifies the maximum number of characters
which can be copied into the string buffer. This must include space
for the terminating null character. If lpszFileUrl is NULL
this value should be zero.
Return Value
If the function succeeds, the return value is the number of characters
copied into the lpszFileUrl buffer, not including the
terminating null character. If a buffer is provided, it must be large
enough to contain the entire URL or the function will fail. If the
lpszFileUrl parameter is NULL, the function will return the length
of the URL and nothing will be copied. If the function fails, it will
return zero. To get extended error information, call the
FtpGetLastError function.
Remarks
The FtpGetFilePathUrl function will return the URL associated
with the specified file path. This can be useful if you wish to display
or store URLs rather than relative paths to a file on the current server.
For example, if you are connected to the server example.com
on port 21 using a standard connection and you provide a relative file
path such as documents/invoice.pdf this function would
return a URL which looks like ftp://example.com/documents/invoice.pdf.
For security reasons, the resulting URL will never contain user
credentials.
The file path in the URL will be normalized to remove extraneous
directory traversals and path separators. If the path is relative, it
will be expanded to an absolute path based on the client's current working
directory. If an absolute path is provided, it will be included in the
URL as-is. It is not required for the file path to exist on the server
at the time this function is called. For more information about path
normalization, refer to the FtpNormalizePath function.
This function can also be used to obtain a URL which can be passed
to the FtpGetSercurityZoneId function to determine which
security zone should be assigned to the file when it is downloaded.
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
Example
The following example shows how FtpGetFilePathUrl could be
used to obtain the origin URL for a file on the server and then use
that in conjunction with the FtpGetSecurityZoneId function to
update the security zone metadata for the file if the download is
successful.
LPCTSTR lpszLocalFile = _T("\\Users\\Public\\Documents\\Document.pdf");
LPCTSTR lpszRemoteFile = _T("files/document.pdf");
TCHAR szFileUrl[FTP_MAXURLPATHLEN] = { 0 };
DWORD dwZoneId = SECURITY_ZONE_NONE;
if (FtpGetFilePathUrl(hClient, lpszRemoteFile, szFileUrl, FTP_MAXURLPATHLEN) < 1)
{
_tprintf(_T("Unable to get URL for \"%s\"\n"), lpszRemoteFile);
return;
}
if (!FtpGetSecurityZoneId(szFileUrl, &dwZoneId))
{
_tprintf(_T("Unable to determine a security zone for \"%s\"\n"), szFileUrl);
}
INT nResult = FtpGetFile(hClient, lpszLocalFile, lpszRemoteFile, 0, 0);
if (nResult != FTP_ERROR)
{
if (dwZoneId != SECURITY_ZONE_NONE)
{
if (!FtpSetFileZoneInfo(lpszLocalFile, dwZoneId, szFileUrl))
{
_tprintf(_T("Unable to set the security zone for \"%s\"\n"), lpszLocalFile);
return;
}
}
}
else
{
_tprintf(_T("Unable to download \"%s\" to \"%s\"\n"), lpszRemoteFile, lpszLocalFile);
}
See Also
|
|