MFC Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

MFC Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DKIM / DomainKey
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

WSAECONNRESET An existing connection was forcibly closed by the remote host.

Explains the meaning of the "WSAECONNRESET An existing connection was forcibly closed by the remote host." error and demonstrates a way to reproduce it by setting the "No Transfer Timeout" setting on a FileZilla FTP server to a very small value.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
// Needs #include <CkFtp2.h>

    CkString strOut;

    CkFtp2 ftp;

    bool success;

    //  Any string unlocks the component for the 1st 30-days.
    success = ftp.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        strOut.append(ftp.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    ftp.put_Hostname("192.168.1.108");
    ftp.put_Username("myLogin");
    ftp.put_Password("myPassword");

    //  Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        strOut.append(ftp.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    ftp.put_Passive(true);

    //  In this example, we've set the FileZilla FTP Server's
    //  "No Transfer Timeout" to 5 seconds.  This is a setting
    //  on the FTP server (not in the Chilkat FTP component).
    //  It causes the server to disconnect from the client after
    //  5 seconds of no upload or download activity.  As you'll see,
    //  sending commands over the control channel, such as
    //  NOOP (no-operation) commands will have no effect.
    //  It is an upload, download, or directory listing that is required.

    //  This code will wait 10 seconds before proceeding with
    //  the PutFile.  This should be enough time for the FileZilla
    //  server to disconnect.
    long i;
    for (i = 0; i <= 10; i++) {
        //  Sleep for 1 second
        ftp.SleepMs(1000);

        //  Send a NOOP command to the FTP server.
        //  After about 5 iterations, it should fail and the LastErrorText
        //  will contain this message:
        //  WSAECONNRESET An existing connection was forcibly closed by the remote host.
        success = ftp.Noop();
        if (success != true) {
            strOut.append(ftp.lastErrorText());
            strOut.append("\r\n");
            break;
        }

    }

    //  What happens if we try to upload a file without an existing
    //  connection?
    //  Let's do it and find out...

    //  Upload a file.
    const char * localFilename;
    localFilename = "c:/temp/hamlet.xml";
    const char * remoteFilename;
    remoteFilename = "hamlet.xml";

    success = ftp.PutFile(localFilename,remoteFilename);
    if (success != true) {

        //  In Active mode (i.e. non-passive), we get this error:
        //  "Failed to get socket's IP address. Socket may already be disconnected."
        //  In Passive mode, we'll get this error:
        //  " No socket exists for sending (2)"
        strOut.append(ftp.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    ftp.Disconnect();

    strOut.append("File Uploaded!\r\n");

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.