CFtpGet - FTP File Retrieval Class | CodeGuru

CFtpGet – FTP File Retrieval Class

Environment: Windows 98, Visual C++ 6 I created this class because I needed a class to allow me to synchronize my local system with files on a remote system. At first, I looked to MSDN for help, but couldn’t get their examples to work. Then, I looked to CodeGuru for assistance. I posted the question […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 7, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Windows 98, Visual C++ 6

I created this class because I needed a class to allow me to synchronize
my local system with files on a remote system. At first, I looked to MSDN for
help, but couldn’t get their examples to work. Then, I looked to CodeGuru for
assistance. I posted the question of how to retreive a file using FTP and
Ken Sutherland was able to help me.

The source code he gave me worked for only one file transfer at a time so
I modified it for my purpose so that it allows for up to 100 files to
be transferred on one operation.

CFtpGet Class Definition

// ftpget.h

class CFtpGet
{
public:// function, in logical order
 CFtpGet();
 virtual ~CFtpGet();

 // password & user name
 bool SetAccessRight(CString userName,CString userPass);

 // open the connection
 bool OpenConnection(CString server);

 // only one file
 bool GetFile(CString remoteFile,
 CString localFile);

 // a full CString array
 int GetMultipleFile(CStringArray *remoteArray,
                     CStringArray *localArray,
                     int number_file);

 // close the connection
 bool CloseConnection();

private: // var
 CInternetSession *pInternetSession;
 CFtpConnection *pFtpConnection;
 CString strServerName;
 CString strPass;
 CString strUser;

public:
 CString strAppName;
 bool missed[100];
};

Using the CFtpGet Class

To transfer a single file…

CFtpGet ftp; //start the class
ftp.SetAccessRight("username","userpassword");// set user and pasword
bool good = ftp.OpenConnection("server");// the name of the server

if (!good)
 return;

ftp.GetFile("somefile.zip","c:\downlaod\myfile.zip");

// see GetMultiplefile below
ftp.CloseConnection();

To transfer multiple files…

CStringArray remote;
CStringArray local;

remote.Add("remote1.zip");
remote.Add("remote2.zip");
remote.Add("remote3.zip");
local.Add("local1.zip");
local.Add("local2.zip");
local.Add("local3.zip");

ftp.GetMultipleFile(&remote,&local,3);

This is my first Itnernet file transfer class and I’ll try to embelish this class as
time permits.

Advertisement

Downloads

Download demo project – 8 Kb
Download source – 16 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.