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 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.

Downloads

Download demo project - 8 Kb
Download source - 16 Kb


Comments

  • Error

    Posted by Legacy on 07/24/2002 12:00am

    Originally posted by: Mathias

    After a ftp connection is open, it could�t close correctly ....
    So ... if you want to reconnect , the older connection will cause problems....

    Reply
  • CInternetSession() argument missing

    Posted by Legacy on 01/11/2002 12:00am

    Originally posted by: Keith Berson

    Maybe it's new with version 6.0 of Visual Studio, but I show the second argument of CInternetSession() as being the context. You have

    CInternetSession(strAppName,INTERNET_OPEN_TYPE_PRECONFIG);

    and it should be

    CInternetSession(strAppName,dwContext,INTERNET_OPEN_TYPE_PRECONFIG);

    Of course, this only matters if you are looking to use CInternetSession::OnStatusCallback(), as the default value for the CInternetSession() is INTERNET_OPEN_TYPE_PRECONFIG.

    Keith

    Reply
  • FTP (intranet) to use as Command line argument

    Posted by Legacy on 06/13/2001 12:00am

    Originally posted by: Guru

    How to use FTP in intranet with command line argument...
    
    any help in this will be appreciated.....
    Thanx in advance
    e-mail:gurvider_a@yahoo.com

    Reply
  • Nice and simple but...

    Posted by Legacy on 06/12/2001 12:00am

    Originally posted by: Bev

    Nice and simple but the example only works if I try to retrieve from the root directory of the ftp server.

    Anything in a lower directory is reported as missing.

    Am I missing something?

    Regards

    Bev

    Reply
  • Retreive file attributes from remote system

    Posted by Legacy on 06/05/2001 12:00am

    Originally posted by: Gaby NGONGO

    Is it possible to retreive only those files that are not opened ? In other words, is it possible to read file attributes from the remote system ?

    Reply
  • How can I use different Codepages?

    Posted by Legacy on 03/17/2001 12:00am

    Originally posted by: Gerald Harte

    Hi,

    i use the Visual C++ 6 FTP-Classe to get some File file from a mainfraime!
    But i have one Problem. The mainfraime does use a different codepage as the PC.
    If you take the DOS-FTP under Windows NT, you can use the command 'quote site sbdataconn=(ibm-273)'!
    I have not find out, where i can use this command under MFC!
    Maybe you have got a idea?

    Regards
    Gerald Harte

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • The mobile market is white hot. Building a well-crafted product development plan that addresses market research, strategy, design, and development will provide the greatest chance for success. Each phase of an app's lifecycle is critical to the its overall success and feeds into the next step of the process of product development for the app. This white paper examines the five key phases of mobile app creation, one by one, to understand how they work together to help create a successful mobile app.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date