CFtpClient::NormalizePath Method  
 
INT NormalizePath(
  LPCTSTR lpszFilePath,  
  LPTSTR lpszNormalized,  
  INT nMaxLength  
);
INT NormalizePath(
  LPCTSTR lpszFilePath,  
  CString& strNormalized  
);

The NormalizePath method normalizes a file path using the current client connection.

Parameters

lpszFilePath
A null-terminated string which specifies a file path on the server. This parameter cannot be NULL.
lpszNormalized
A null-terminated string buffer which will contain the normalized path when the method returns. The buffer must be large enough to contain the entire path including the terminating null character. If this parameter is NULL it will be ignored and the method will return the length of the normalized path without copying any characters. An alternate version of this method accepts a reference to a CString object which will contain the normalized path when the method returns.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the string buffer. If this value is zero, the lpszNormalized parameter is ignored and the method will return the length of the normalized path without copying any characters.

Return Value

This method returns the number of characters copied into the string buffer, not including the terminating null character. If the lpszNormalized parameter is NULL, it will return the length of the normalized path but will not copy any characters. If the method fails, it will return FTP_ERROR. To get extended error information, call GetLastError.

Remarks

This method will accept a relative or absolute file path on the server and return a normalized version of that path. Normalization will remove extraneous path delimiters and collapse the path if there are references to parent directories. For example, if the current working directory for the user is /home/jsmith and the file path provided is:

./text/..//data//./files/filename.txt

This method would return the following as the normalized path:

/home/jsmith/data/files/filename.txt

Because the path is relative, the current working directory for the client would be used to create an absolute path. The extraneous path delimiters are removed (the double slashes) and the reference to the parent directory is collapsed to produce a simple, uniform path. This can be useful both for display purposes and to normalize input provided by a user.

If a connection has not been established with a server, relative file paths will not be normalized as absolute paths because there is no current working directory available. This allows the method to be used without an active connection, removing any extraneous path delimiters and collapsing the path without returning an absolute path unless one was provided.

If the path specified by the lpszFilePath parameter is relative to the current directory and there is no active connection, the normalized path returned by the method will always be relative. For example, if the path provided is:

../../../../../data/filename.txt

This method would return the following as the normalized path:

data/filename.txt

Because the original path was relative, the normalized path is also relative and will not begin with a leading path delimiter. It is intentionally designed this way to prevent the path from "escaping" to the root directory of a file system, which can present a security risk. If the original path was absolute, the normalized path would also be absolute.

This method will accept an FTP URL and return only the normalized path and file name potion of the URL. If you need to normalize a complete URL, use the NormalizeUrl method.

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