Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Unicode C) FTP Large File Upload

Demonstrates how to use the LargeFileUpload method introduced in v9.5.0.58.

The LargeFileUpload method is the same as PutFile, but designed to work around the following potential problem associated with an upload that is extremely large.

FTP uses two TCP (or TLS) connections: a control connection to submit commands and receive replies, and a data connection for actual file transfers. It is the nature of FTP that during a transfer the control connection stays completely idle. Many routers and firewalls automatically close idle connections after a certain period of time. Worse, they often don't notify the user, but just silently drop the connection.

For FTP, this means that during a long transfer the control connection can get dropped because it is detected as idle, but neither client nor server are notified. When all data has been transferred, the server assumes the control connection is alive and it sends the transfer confirmation reply.

Likewise, the client thinks the control connection is alive and it waits for the reply from the server. But since the control connection got dropped without notification, the reply never arrives and eventually the connection will timeout.

The Solution: LargeFileUpload uploads the file in chunks, where each chunk appends to the remote file. This way, each chunk is a separate FTP upload that does not take too long to complete. The chunkSize specifies the number of bytes to upload in each chunk. The size should be based on the amount of memory available (because each chunk will reside in memory as it's being uploaded), the transfer rate, and the total size of the file being uploaded. For example, if a 4GB file is uploaded, and the chunkSize is set to 1MB (1,048,576 bytes), then 4000 separate chunks would be required. This is likely not a good choice for chunkSize. A more appropriate chunkSize might be 20MB, in which case the upload would complete in 200 separate chunks. The application would temporarily be using a 20MB buffer for uploading chunks. The tradeoff is between the number of chunks (the more chunks, the larger the overall time to upload), the amount of memory that is reasonable for the temporary buffer, and the amount of time required to upload each chunk (if the chunk size is too large, then the problem described above is not solved).

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkFtp2W.h>

void ChilkatSample(void)
    {
    HCkFtp2W ftp;
    BOOL success;
    const wchar_t *localPath;
    const wchar_t *remoteFilename;
    int chunkSize;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    ftp = CkFtp2W_Create();

    CkFtp2W_putHostname(ftp,L"ftp.someFtpServer.com");
    CkFtp2W_putUsername(ftp,L"my-ftp-login");
    CkFtp2W_putPassword(ftp,L"my-ftp-password");

    // Connect and login to the FTP server.
    success = CkFtp2W_Connect(ftp);
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    // Change to the remote directory where the file will be uploaded.
    success = CkFtp2W_ChangeRemoteDir(ftp,L"junk");
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    localPath = L"c:/temp/veryLargeFile.dat";
    remoteFilename = L"veryLargeFile.dat";
    // Upload in chunks of 10 million bytes.
    chunkSize = 10000000;

    success = CkFtp2W_LargeFileUpload(ftp,localPath,remoteFilename,chunkSize);
    if (success != TRUE) {
        wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
        CkFtp2W_Dispose(ftp);
        return;
    }

    success = CkFtp2W_Disconnect(ftp);

    wprintf(L"Large File Uploaded!\n");


    CkFtp2W_Dispose(ftp);

    }

 

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