Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) FTP Download Text File to a Stream

Demonstrates how to FTP download a text file to a Chilkat stream.

Note: This example requires Chilkat v9.5.0.67 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoFtp
    Boolean iSuccess
    Variant vStreamObj
    Handle hoStreamObj
    Variant vT
    Handle hoT
    String sLine
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatFtp2)) To hoFtp
    If (Not(IsComObjectCreated(hoFtp))) Begin
        Send CreateComObject of hoFtp
    End

    Set ComHostname Of hoFtp To "www.my-ftp-server.com"
    Set ComUsername Of hoFtp To "mFtpLogin"
    Set ComPassword Of hoFtp To "myFtpPassword"
    Set ComAuthTls Of hoFtp To True
    Set ComPassive Of hoFtp To True

    //  Connect and login to the FTP server using TLS.
    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStream)) To hoStreamObj
    If (Not(IsComObjectCreated(hoStreamObj))) Begin
        Send CreateComObject of hoStreamObj
    End

    //  Indicate the charset of the incoming data.
    Set ComStringCharset Of hoStreamObj To "utf-8"

    //  Create a task to do the FTP download.
    Get pvComObject of hoStreamObj to vStreamObj
    Get ComGetFileToStreamAsync Of hoFtp "lines.txt" vStreamObj To vT
    If (IsComObject(vT)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoT
        Set pvComObject Of hoT To vT
    End
    Get ComLastMethodSuccess Of hoFtp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Start the task in a background thread.
    Get ComRun Of t To iSuccess

    //  Read the incoming text data using any of the streamObj Read methods.
    //  This example will read line-by-line.

    While ((ComEndOfStream(hoStreamObj)) <> True)
        Get ComReadToCRLF Of hoStreamObj To sLine
        Get ComLastMethodSuccess Of hoStreamObj To bTemp1
        If (bTemp1 = True) Begin
            Showln sLine
        End

    Loop

    Send Destroy of t

    Showln "Success."


End_Procedure

 

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