CFTPClient

CFtpClient - A FTP client class derived from CSocket.
Although WININET is a great set of API calls for connecting to a FTP Server, it's doesn't give you much control of what's going on 'behind the scenes'. For my utility Pablo Commander I've create the class CFtpClient which is derived from CSocket (it doesn't use WININET API), that gives you complete control over the communication with the FTP server.

Description of the methods:
BOOL Connect(LPCTSTR lpszServer,LPCTSTR lpszUserName,LPCTSTR lpszPassword,
UINT nPort,BOOL bPassiveMode);
Connect to a FTP Server.

Parameters:
lpszServer - FTP server name.
lpszUserName - Name of the user to log in.
lpszPassword - Password to use to log in.
nPort - A number that identifies the TCP/IP port to use on the server.
bPassiveMode - Specifies passive or active mode for this FTP session.

BOOL Disconnect();
Disconnect from FTP server.

BOOL GetCurrentDirectory(CString& strPathName);
Gets the current directory for this connection.

Parameters:
strPathName - string that will receive the name of the directory.

BOOL SetCurrentDirectory(LPCTSTR lpszPathName);
Sets the current FTP directory.

Parameters:
lpszPathName - Name of the directory

BOOL CreateDirectory(LPCTSTR lpszPathName);
Creates a directory on the server.

Parameters:
lpszPathName - Name of the directory to create.

BOOL Rename(LPCTSTR lpszExisting, LPCTSTR lpszNew);
Renames a file or directory on the server.

Parameters:
lpszExisting - current name of the file to be renamed.
lpszNew - the file’s new name.

BOOL Remove(LPCTSTR lpszPathName);
Remove a file from the server.

Parameters:
lpszPathName - file name to remove

BOOL RemoveDirectory(LPCTSTR lpszPathName, BOOL bRecursive);
Removes the specified directory from the server.

Parameters:
lpszPathName - directory to be removed
bRecursive - if recursive is set the directory and all it's contents will be deleted.

BOOL FindFile(LPCTSTR lpszPathName);
Finds a file on a FTP server (Retrieve directory listing)
Used in combination with FindNextFile.

Parameters:
lpszPathName - name of the file or directory to find.

BOOL FindNextFile(CFileStatus &rStatus);
Continues a file search from a previous call to FindFile

Parameters:
rStatus - structure that will receive the properties of the current file.

BOOL SetDirStyle(BOOL bUnixStyle);
IIS FTP Server supports two types of directory styles: UNIX and DOS style.
This method allows you to set the directory style of the server.

BOOL GetFile(LPCTSTR lpszRemoteFile, LPCTSTR lpszLocalFile, BOOL bFailIfExists,
BOOL bBinary, BOOL bResume, LPPROGRESSCALLBACK lpfnProgressCallback);

Gets a file from the connected server

Parameters:
lpszRemoteFile - name of a file to retrieve from the FTP server.
lpszLocalFile - name of the file to create on the local system.
bFailIfExists - indicates whether the file name may already be used by an existing file.
bBinary - Transfer mode: BINARY if TRUE else ASCII.
bResume - resume file transfer if previous download was interrupted
lpfnProgressCallback - Pointer to callback function to implement progress status.

BOOL PutFile(LPCTSTR lpszLocalFile, LPCTSTR lpszRemoteFile, BOOL bBinary,
DWORD dwRestartOffset, LPPROGRESSCALLBACK lpfnProgressCallback);

Places a file on the server

Parameters:
lpszLocalFile - name of the file to send from the local system.
lpszRemoteFile - name of the file to create on the FTP server.
bBinary - Transfer mode: BINARY if TRUE else ASCII.
dwRestartOffset - resume file transfer at this position.
lpfnProgressCallback - Pointer to callback function to implement progress status.

BOOL PutFile(CFtpClient *pConnection, LPCTSTR lpszSourceFile, LPCTSTR lpszDestinationFile, BOOL bBinary, DWORD dwRestartOffset, LPPROGRESSCALLBACK lpfnProgressCallback);
Copies a file from one FTP server to another.

Parameters:
pConnection - Pointer to the FTP connection where the source file is located.
lpszSourceFile - name of the file to send from the source FTP server.
lpszDestinationFile - name of the file to create on the FTP server.
bBinary - Transfer mode: BINARY if TRUE else ASCII.
dwRestartOffset - resume file transfer at this position.
lpfnProgressCallback - Pointer to callback function to implement progress status.

Download demo executable

Download source code
This class is part of the Pablo Software Solutions MFC Extension Package - Classes Edition

 

[Home] [Products] [Source Code] [Downloads] [Support]

© 2015 - Pablo Software Solutions
All rights reserved.