FtpOpenFile Function  
 
INT WINAPI FtpOpenFile(
  HCLIENT hClient,  
  LPCTSTR lpszFileName,  
  DWORD dwOpenMode,  
  DWORD dwOffset  
);

The FtpOpenFile function creates or opens the specified file on the server.

Parameters

hClient
Handle to the client session.
lpszFileName
Points to a string that specifies the name of the remote file to create or open. The file pathing and name conventions must be that of the server.
dwOpenMode
Specifies the type of access to the file. An application can open a file for reading, create a new file or append data to an existing file. This parameter should be one of the following values.
Value Description
FTP_FILE_READ The file is opened for reading on the server. A data channel is created and the contents of the file are returned to the client.
FTP_FILE_WRITE The file is opened for writing on the server. If the file does not exist, it will be created. If it does exist, it will be overwritten.
FTP_FILE_APPEND The file is opened for writing on the server. All data will be appended to the end of the file.
dwOffset
A byte offset which specifies where the file transfer should begin. The default value of zero specifies that the file transfer should start at the beginning of the file. A value greater than zero is typically used to restart a transfer that has not completed successfully. Note that specifying a non-zero offset using FTP requires that the server support the REST command to restart transfers.

Return Value

If the function succeeds, the return value is the server result code. If the function fails, the return value is FTP_ERROR. To get extended error information, call FtpGetLastError.

Remarks

Only one file may be opened at a time for each client session. Attempting to perform an action such as uploading or downloading another file while a file is currently open will result in an error. Typically this indicates that the application failed to call the FtpCloseFile function.

When a file is created on the server, the file ownership and access rights are determined by the server. Some servers may provide a method to change these attributes through site-specific commands. Refer to the server's operating system documentation for more information about what commands may be available.

It is recommended that most applications use the FtpGetFile or FtpPutFile functions to perform file transfers. These functions are easier to use, and have internal optimizations that improves the overall data transfer rate when compared to implementing the file transfer code in your own application.

This function uses a 32-bit unsigned integer (DWORD) to represent the file offset, which limits the maximum size to 4 GiB minus one byte (4,294,967,295 bytes). When working with files that may exceed this limit, applications should use the FtpOpenFileEx function, which uses a 64-bit ULARGE_INTEGER structure to represent these values. The extended version supports large files while maintaining compatibility with the original function.

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