Java FTP component
This Java FTP component provides an easy to use API for the transfer
of files to / from an FTP server. Written using 100% Java and delivered
as a Java Bean, this Java FTP client is usable in a wide variety
of IDE and platform configurations. Download
Secure iNet Factory Evaluation
Other related JSCAPE products include:
Secure FTP Factory
JSCAPE Secure FTP Server
Secure FTP Applet
Features
- Transfer mode support - Includes both ASCII and Binary modes
for transferring text or binary data.
- Firewall support - Easily connect to FTP servers from behind
a firewall.
- Security - Support for secure FTPS and SFTP protocols.
- Automatic transfer mode detection - Sets transfer mode automatically
based on file extension.
- Multiple file transfer - Transfer one or more files matching
a regular expression e.g. *.txt
- Directory transfer - Transfer entire directories recursively,
automatically recreating directory structure on receiving side.
- Progress monitor - Built in event listeners to track the progress
of file transfers including bytes transferred, total time and
total bytes transferred.
- Timeout support - Generates an exception when connection to
FTP server cannot be established or data cannot be read from FTP
server within defined timeout.
- File transfer interruption - Ability to interrupt file transfers
at any time.
- Message logging - Ability to stream messages exchanged between
FTP client and server to a file.
- Memory based uploads - Ability to upload a file that exists
in memory to FTP server.
- Memory based downloads - Ability to download file from FTP server
and store in memory.
- Remote filesize and date - Easily query a remote file on FTP
server for it's size and last modification timestamp.
- Command execution - Send arbitrary commands to FTP server.
- Append support - Upload files to FTP server appending data sent
to the end of of a file.
- Resume support - Resume interrupted file transfers.
- File integrity - Verify the integrity of transferred files.
Code Example
The following example demonstrates how to connect to an FTP server
and perform a directory listing.
/*
* @(#)FtpExample.java
*
* Copyright (c) 2001-2002 JScape
* 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* JScape. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with JScape.
*/
import com.jscape.inet.ftp.*;
import java.io.*;
import java.util.Enumeration;
public class FtpExample extends FtpAdapter {
private String hostname;
private String username;
private String password;
public FtpExample(String hostname, String username, String password) {
this.hostname = hostname;
this.username = username;
this.password = password;
}
// print out directory listing
public void getListing() throws FtpException {
// create new Ftp instance with hostname, username and password arguments
Ftp ftp = new Ftp(hostname,username,password);
// register this class to capture FTP related events
ftp.addFtpListener(this);
// connect to FTP server
ftp.connect();
// get results of a directory listing
String results = ftp.getDirListingAsString();
// print out directory listing results
System.out.println(results);
// disconnect from FTP server
ftp.disconnect();
}
// captures connect event
public void connected(FtpConnectedEvent evt) {
System.out.println("Connected to server: " + evt.getHostname());
}
// captures disconnect event
public void disconnected(FtpDisconnectedEvent evt) {
System.out.println("Disconnected from server: " + evt.getHostname());
}
public static void main(String[] args) {
String hostname;
String username;
String password;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Ftp hostname (e.g. ftp.microsoft.com): ");
hostname = reader.readLine();
System.out.print("Enter username (e.g. anonymous): ");
username = reader.readLine();
System.out.print("Enter password (e.g. user@here.com): ");
password = reader.readLine();
FtpExample example = new FtpExample(hostname,username,password);
example.getListing();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
|
|