public class Ftp
extends java.lang.Object
File Transfer Protocol client class. Provides basic FTP client functionality in an Asynchronous interface.
see rfc959.
Ftp ftp = new Ftp(InetAddress.getByName("RemoteHost"), "TestUser", "TestPass"); ftp.setType(Ftp.IMAGE); ftp.startGet("RemoteFileName", "LocalFileName"); ftp.waitUntilTransferComplete(); ftp.startPut("LocalFileName", "RemoteFileName"); ftp.waitUntilTransferComplete();
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
anonymous |
static char |
ASCII |
static char |
BINARY |
static char |
CARRIAGE_CONTROL |
static int |
defaultPort |
static char |
EBCDIC |
static char |
IMAGE |
static char |
LOCAL |
static char |
NON_PRINT |
static char |
TELNET |
Constructor and Description |
---|
Ftp()
Ftp constructor
|
Ftp(java.net.InetAddress hostAddr,
int port,
java.lang.String username,
java.lang.String password)
Ftp constructor Construct an FTP endpoint, open the command port and authenticate the user.
|
Ftp(java.net.InetAddress hostAddr,
java.lang.String username,
java.lang.String password)
Ftp constructor Construct an FTP endpoint, open the default command port and authenticate the
user.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Abort transfer command
|
void |
authenticate(java.lang.String username,
java.lang.String password)
Authenticate User
|
void |
close()
close the FTP session
|
void |
delete(java.lang.String remoteName)
Delete remote file
|
java.lang.String |
getLastModifiedTime(java.lang.String remoteName) |
java.net.InetAddress |
getLocalAddress() |
java.lang.String |
getSize(java.lang.String remoteName) |
void |
getUrl(java.lang.String url,
java.io.OutputStream out)
Get file from a URL spec
|
java.util.Vector |
list()
Get list files in remote working directory
|
java.util.Vector |
list(java.lang.String mask)
Get a directory listing from the remote server.
|
static void |
main(java.lang.String[] args) |
void |
mkdir(java.lang.String remoteName)
Create remote directory
|
void |
open(java.net.InetAddress hostAddr)
Open connection
|
void |
open(java.net.InetAddress hostAddr,
int port)
Open connection
|
void |
rename(java.lang.String oldName,
java.lang.String newName)
Rename remote file
|
void |
rmdir(java.lang.String remoteName)
Delete remote directory
|
void |
sendFile(java.lang.String srcName,
java.net.InetAddress destAddr,
int destPort,
java.lang.String username,
java.lang.String password,
java.lang.String destName)
send file Do a file transfer remote file to remote file on another server.
|
void |
setType(char type)
Set the connection data type.
|
void |
setType(char type,
char param)
Set the connection data type.
|
void |
setType(int length)
Set the connection data type to Local.
|
java.io.InputStream |
startGet(java.lang.String remoteName)
Start get file Start a file transfer remote file to local inputStream.
|
void |
startGet(java.lang.String remoteName,
java.io.OutputStream destination)
Start get file Start a file transfer remote file to local file.
|
void |
startGet(java.lang.String remoteName,
java.lang.String localName)
Start get file Start a file transfer remote file to local file.
|
void |
startPasvGet(java.lang.String remoteName,
java.io.OutputStream destination) |
void |
startPasvGet(java.lang.String remoteName,
java.lang.String localName)
Start passive get file Start a file transfer remote file to local file.
|
void |
startPasvPut(java.io.InputStream source,
java.lang.String remoteName) |
void |
startPasvPut(java.lang.String localName,
java.lang.String remoteName)
Start passive put file Start a file transfer local file to input remote file.
|
void |
startPut(java.io.InputStream source,
java.lang.String remoteName)
Start put file Start a file transfer local file to input remote file.
|
java.io.OutputStream |
startPut(java.lang.String remoteName)
Start put file Start a file transfer local file to input remote file.
|
void |
startPut(java.lang.String localName,
java.lang.String remoteName)
Start put file Start a file transfer local file to input remote file.
|
java.lang.String |
status()
Get remote server status
|
boolean |
transferComplete()
Command complete query
|
protected void |
transferCompleteNotification()
Transfer completion notification.
|
void |
waitUntilTransferComplete()
Wait until Transfer is complete.
|
java.lang.String |
workingDirectory()
Report remote working directory
|
void |
workingDirectory(java.lang.String dir)
Set remote working directory
|
public static final java.lang.String anonymous
public static final int defaultPort
public static final char ASCII
public static final char LOCAL
public static final char EBCDIC
public static final char IMAGE
public static final char BINARY
public static final char NON_PRINT
public static final char TELNET
public static final char CARRIAGE_CONTROL
public Ftp()
public Ftp(java.net.InetAddress hostAddr, java.lang.String username, java.lang.String password) throws FtpException, java.io.IOException
hostAddr
- The IP address of the remote hostusername
- User name for authentication, null implies no user requiredpassword
- Password for authentication, null implies no passwordFtpException
- For local problems or negative server responsesjava.io.IOException
public Ftp(java.net.InetAddress hostAddr, int port, java.lang.String username, java.lang.String password) throws FtpException, java.io.IOException
hostAddr
- The IP address of the remote hostport
- The port to use for the control connection. The default value is used if the port
is 0.username
- User name for authentication, null implies no user requiredpassword
- Password for authentication, null implies no passwordFtpException
- For local problems or negative server responsesjava.io.IOException
public java.net.InetAddress getLocalAddress()
public void open(java.net.InetAddress hostAddr) throws FtpException, java.io.IOException
hostAddr
- The IP address of the remote hostFtpException
- For local problems or negative server responsesjava.io.IOException
public void open(java.net.InetAddress hostAddr, int port) throws FtpException, java.io.IOException
hostAddr
- The IP address of the remote hostport
- The port to use for the control connection. The default value is used if the port
is 0.FtpException
- For local problems or negative server responsesjava.io.IOException
public void authenticate(java.lang.String username, java.lang.String password) throws FtpException, java.io.IOException
username
- User name for authentication, null implies no user requiredpassword
- Password for authentication, null implies no passwordFtpException
- For local problems or negative server responsesjava.io.IOException
public void setType(char type) throws FtpException, java.io.IOException
type
- One of Ftp.ASCII, Ftp.EBCDIC or Ftp.IMAGEFtpException
- For local problems or negative server responsesjava.io.IOException
- IOExceptionpublic void setType(char type, char param) throws FtpException, java.io.IOException
type
- One of Ftp.ASCII or Ftp.EBCDICparam
- One of Ftp.NON_PRINT, Ftp.TELNET or Ftp.CARRIAGE_CONTROLFtpException
- For local problems or negative server responsesjava.io.IOException
- IOExceptionpublic void setType(int length) throws FtpException, java.io.IOException
length
- Length of word.FtpException
- For local problems or negative server responsesjava.io.IOException
- IOExceptionpublic boolean transferComplete() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responses. The problem may have
been detected before the call to complete during a data transfer, but is only
reported when the call to complete is made.java.io.IOException
public void waitUntilTransferComplete() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
protected void transferCompleteNotification()
public void startGet(java.lang.String remoteName, java.lang.String localName) throws FtpException, java.io.IOException
remoteName
- Remote file namelocalName
- Local file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public java.io.InputStream startGet(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- Remote file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void startGet(java.lang.String remoteName, java.io.OutputStream destination) throws FtpException, java.io.IOException
remoteName
- Remote file namedestination
- OutputStream to which the received file is writtenFtpException
- For local problems or negative server responsesjava.io.IOException
public void startPut(java.lang.String localName, java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- Remote file namelocalName
- Local file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public java.io.OutputStream startPut(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- Remote file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void startPut(java.io.InputStream source, java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- Remote file namesource
- FtpException
- For local problems or negative server responsesjava.io.IOException
public void startPasvGet(java.lang.String remoteName, java.lang.String localName) throws FtpException, java.io.IOException
remoteName
- Remote file namelocalName
- Local file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void startPasvGet(java.lang.String remoteName, java.io.OutputStream destination) throws FtpException, java.io.IOException
FtpException
java.io.IOException
public void startPasvPut(java.lang.String localName, java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- Remote file namelocalName
- Local file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void startPasvPut(java.io.InputStream source, java.lang.String remoteName) throws FtpException, java.io.IOException
FtpException
java.io.IOException
public void mkdir(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- The remote directory nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void sendFile(java.lang.String srcName, java.net.InetAddress destAddr, int destPort, java.lang.String username, java.lang.String password, java.lang.String destName) throws FtpException, java.io.IOException
srcName
- Remote file name on source serverdestAddr
- The IP address of the destination hostdestPort
- The port to use for the control connection. The default value is used if the
port is 0.username
- User name for authentication, null implies no user requiredpassword
- Password for authentication, null implies no passwordFtpException
- For local problems or negative server responsesjava.io.IOException
public java.lang.String workingDirectory() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public void workingDirectory(java.lang.String dir) throws FtpException, java.io.IOException
dir
- The remote working directoryFtpException
- For local problems or negative server responsesjava.io.IOException
public void rename(java.lang.String oldName, java.lang.String newName) throws FtpException, java.io.IOException
oldName
- The original file namenewName
- The new file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void delete(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- The remote file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public void abort() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public java.util.Vector list() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public java.lang.String status() throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public void close() throws java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public void getUrl(java.lang.String url, java.io.OutputStream out) throws FtpException, java.io.IOException
url
- string of the form: "ftp://username:password@host:port/path/to/file"out
- the OutputStream to place the fetched file inFtpException
java.io.IOException
public void rmdir(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- The remote directory nameFtpException
- For local problems or negative server responsesjava.io.IOException
public java.lang.String getLastModifiedTime(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- The remote file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public java.lang.String getSize(java.lang.String remoteName) throws FtpException, java.io.IOException
remoteName
- The remote file nameFtpException
- For local problems or negative server responsesjava.io.IOException
public java.util.Vector list(java.lang.String mask) throws FtpException, java.io.IOException
FtpException
- For local problems or negative server responsesjava.io.IOException
public static void main(java.lang.String[] args)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.