Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to know Progress of CFtpConnection::GetFile()

suhredayansuhredayan Posts: 69Member
How to know Progress of CFtpConnection::GetFile()function. That is no: of bytes received till now.
I tried by overriding OnStatusCallback() . But once started transfer this function was called only once.

Comments

  • DB1DB1 Posts: 1,142Member
    : How to know Progress of CFtpConnection::GetFile()function. That is no: of bytes received till now.
    : I tried by overriding OnStatusCallback() . But once started transfer this function was called only once.
    :

    The CFtpConnection::GetFile() function is a high level function that basically automates everything for you. You cannot find the files' size, or how much of the file has been downloaded from it. You need to use another method of retrieving the file from the ftp server, incorporating a while(loop) to read the remote file, and count the bytes read.

    BTW, this message board turns the ftp functions to blue links, you have to reply to this message to read what I really wrote where the links are. Hope this helps.
    [code]
    non-complete code snippet:

    CFtpConnection *ftpSession;
    CStdioFile *fTargFile;

    ftpSession = netSession.GetFtpConnection(strServerName, ftpUsername, ftpPassword);

    CFtpFileFind ftpFind(ftpSession);

    BOOL bContinue = ftpFind.FindFile(strFilePath);

    while (bContinue)
    {
    bContinue = ftpFind.FindNextFile();
    CString NewName = ftpFind.GetFileName();
    while ( -1 != NewName.Find('/',0) )
    {
    NewName.Delete(0,1);
    }
    filesize = ftpFind.GetLength();
    }
    ftpFind.Close();

    fTargFile = ftpSession->OpenFile(strFilePath, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY);


    int byteswrite;
    char filebuf[512];

    while (byteswrite = fTargFile->Read(filebuf, 512))
    {

    [green]// write it to fDestFile, keep track of bytes read / filesize here
    }
    [/code]

    [italic][blue]Programming is like kids... One mistake and you have to support it for life[/blue][/italic]

Sign In or Register to comment.