Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#C# WinRTDelphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET WinRTVBScript

Java Examples

Certificates
Email Object
Encryption
FTP
HTML-to-XML/Text
Gzip
HTTP
IMAP
MHT / HTML Email
PFX/P12
Java KeyStore (JKS)
POP3
RSA Encryption
MIME
SMTP
Socket/SSL/TLS
SSH Key
SSH
SFTP
Tar Archive
XML
XMP
Zip

More Examples...
Amazon S3
Bounced Email
CSV
Diffie-Hellman
DKIM / DomainKey
NTLM

 

 

 

 

 

 

 

(Java) Passive FTP Upload

Simple example to upload a file to an FTP server using passive mode.

Chilkat Java Downloads

Java Libs for Windows, Linux, MAC OS X

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkFtp2 ftp = new CkFtp2();

    boolean success;

    //  Any string unlocks the component for the 1st 30-days.
    success = ftp.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        System.out.println(ftp.lastErrorText());
        return;
    }

    ftp.put_Hostname("www.example-code.com");
    ftp.put_Username("***");
    ftp.put_Password("***");

    //  Use Passive mode.
    ftp.put_Passive(true);

    //  Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        System.out.println(ftp.lastErrorText());
        return;
    }

    //  Change to the remote directory where the file will be uploaded.
    success = ftp.ChangeRemoteDir("junk");
    if (success != true) {
        System.out.println(ftp.lastErrorText());
        return;
    }

    //  Upload a file.
    String localFilename = "hamlet.xml";
    String remoteFilename = "hamlet.xml";

    success = ftp.PutFile(localFilename,remoteFilename);
    if (success != true) {
        System.out.println(ftp.lastErrorText());
        return;
    }

    ftp.Disconnect();

    System.out.println("File Uploaded!");

  }
}

 

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