Documentation
How to use
Using CleanFTP library is fairly simple:
- Instantiate the CleanFTP class;
- Connect and log in to the FTP server;
- Do work and...
- 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.
|