CFtpClient::GetFilePathUrl Method  
 
INT GetFilePathUrl(
  LPCTSTR lpszFilePath,  
  LPTSTR lpszFileUrl,  
  INT nMaxLength  
);
INT GetFilePathUrl(
  LPCTSTR lpszFilePath,  
  CString& strFileUrl  
);

The FtpGetFilePathUrl method returns a normalized URL for the specified file on the server.

Parameters

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 method will return the length of the URL, not including the terminating null character. An alternate version of this method accepts a reference to a CString object.
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 method 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 method will fail. If the lpszFileUrl parameter is NULL, the method will return the length of the URL and nothing will be copied. If the method fails, it will return zero. To get extended error information, call the GetLastError method.

Remarks

The GetFilePathUrl method 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 method 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 method is called. For more information about path normalization, refer to the NormalizePath method.

This method can also be used to obtain a URL which can be passed to the GetSercurityZoneId method 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

See Also