Home
SourceForge Project

Project

About
License
Download

Documentation

How to use
Monitoring file transfers
Directory listing parsers
Java docs

 

Crafted with jEdit

Documentation

How to use

Using CleanFTP library is fairly simple:

  1. Instantiate the CleanFTP class;
  2. Connect and log in to the FTP server;
  3. Do work and...
  4. Close the connection.

import net.sf.cleanftp.CleanFTP;
import java.io.File;

    .
    .
    CleanFTP ftp = new CleanFTP();

    try {
        if (ftp.openConnection("ftp.yourserver.com", 21)) {
            if (ftp.login("joe", "secret")) {
                ftp.upload(new File("foo.txt"), "/bar/foo/foo.txt");
            }
        }
        ftp.quit();
        ftp.closeConnection();
    }
    catch (Exception ex) { ... }
    .
    .

Monitoring file transfers

You can monitor a file transfer process (download or upload) by registering a listener into your CleanFTP instance. For example:

import net.sf.cleanftp.CleanFTP;
import net.sf.cleanftp.DownloadStatus;
import net.sf.cleanftp.FileTransferListener;
import net.sf.cleanftp.UploadStatus;

    .
    .
    ftp.addFileTransferListener(new MyTransferListener());
    .
    .
    
class MyTransferListener implements FileTransferListener {

    public void downloadStatusChanged(DownloadStatus status) {
         // your code to monitor downloads...
    }
    
    public void uploadStatusChanged(UploadStatus status) {
         // your code to monitor uploads...
    }
    
}

The binaries download contains two complete working examples on how to monitor file transfers.

Directory listing parsers

I think the most difficult work in that kind of library is the directory listing parse. I wrote a parser for the standard *nix listing and no other. But you can write a parser that fit your own needs. If you do so, why not share your work? :-)

You'll find more information about writing your own directory listing parses in the net.sf.cleanftp.file package documentation.

Java docs

The binaries download also contains the javadocs but you can browse the javadocs on-line.

 

CleanFTP Library. Licensed under the Apache License 2.0
Copyright 2007 Daniel "Spanazzi" Gonçalves