public class FtpClient
extends java.lang.Object
ftpClient = new FtpClient(); try { ftpClient.connect("10.0.100.206",21,"adm","adm"); ftpClient.setActivePortRange(10000,20000); ftpClient.setActive(); String[] dirList = ftpClient.dir(""); for (int i=0; i< dirList.length; i++) { System.out.println(dirList[i]); } } catch (IO Exception io) { System.out.println ("Handle IOException caught:"+e); } catch (FtpCException f) { System.out.println ("Handle FtCException caught:"+f); } finally { ftpClient.disconnect(); }
Constructor and Description |
---|
FtpClient()
Create an instance of FtpClient.
|
Modifier and Type | Method and Description |
---|---|
void |
connect(java.lang.String host)
Connects to the default port of an FTP server and logs in as anonymous/anonymous.
|
void |
connect(java.lang.String host,
int Port)
Connects to an FTP server and logs in as anonymous/anonymous.
|
void |
connect(java.lang.String host,
int Port,
java.lang.String user,
java.lang.String pass)
Connects to an FTP server and logs in with the supplied username and password.
|
void |
cwd(java.lang.String dir)
Changes working directory.
|
void |
delete(java.lang.String fileName)
Deletes a file
|
java.lang.String[] |
dir(java.lang.String dir)
Lists the contents of a directory
|
java.lang.String[] |
dir(java.lang.String dir,
java.lang.String attr)
Lists the contents of a directory according to specified attributes
|
void |
disconnect()
Disconnects from the FTP server.
|
void |
get(java.io.OutputStream oStream,
java.lang.String remote)
gets a file from the remote server
|
void |
get(java.lang.String local,
java.lang.String remote)
gets a file from the remote server
|
java.lang.String |
getVersion()
get current version of java FTP client library
|
void |
mkd(java.lang.String dir)
Creates a new directory.
|
void |
noop()
Triggers ok reply from server side
|
void |
put(java.io.InputStream iStream,
java.lang.String remote)
Stores an input stream on the remote server
|
void |
put(java.lang.String local,
java.lang.String remote)
Stores a file on the remote server
|
java.lang.String |
pwd()
Returns the present working directory.
|
void |
rmd(java.lang.String dir)
Deletes a directory
|
boolean |
setActive()
Sets active mode: data connections will be set up
in active mode.
|
void |
setActivePortRange(int Lowest,
int Highest)
Sets the port range to use when data connections are set up in active mode.
|
void |
setBin()
Sets Binary mode
|
void |
setPassive()
Sets passive mode: data connections will be set up in passive mode.
|
public void connect(java.lang.String host) throws java.io.IOException, FtpCException
host
- hostname or IP address of the serverIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when already connected.java.io.IOException
FtpCException
public void connect(java.lang.String host, int Port) throws java.io.IOException, FtpCException
host
- server hostname or server IP addressPort
- server portIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when already connected.java.io.IOException
FtpCException
public void connect(java.lang.String host, int Port, java.lang.String user, java.lang.String pass) throws java.io.IOException, FtpCException
host
- server hostname or server IP addressPort
- server portuser
- usernamepass
- user passwordIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when already connected.java.io.IOException
FtpCException
public void disconnect()
public void setPassive() throws FtpCException
FtpCException
- thrown when not connected to the FTP server.FtpCException
public void setActivePortRange(int Lowest, int Highest) throws FtpCException
Lowest
- indicate lowest port of the port rangeHighest
- indicate highest port of the port rangeFtpCException
- thrown when an invalid port range is specified.FtpCException
public boolean setActive() throws FtpCException
FtpCException
- thrown when not connected to the FTP server.FtpCException
public void cwd(java.lang.String dir) throws java.io.IOException, FtpCException
dir
- destination directoryIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public java.lang.String pwd() throws java.io.IOException, FtpCException
IOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void mkd(java.lang.String dir) throws java.io.IOException, FtpCException
dir
- directory name of the directory to be createdIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void rmd(java.lang.String dir) throws java.io.IOException, FtpCException
dir
- directory name of the directory to be removedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void noop() throws java.io.IOException, FtpCException
IOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void put(java.lang.String local, java.lang.String remote) throws java.io.IOException, FtpCException
local
- file name of the file to be stored on the serverremote
- file name on the server of the file to be storedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void put(java.io.InputStream iStream, java.lang.String remote) throws java.io.IOException, FtpCException
iStream
- input stream to be storedremote
- file name on the server of the file to be storedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void get(java.lang.String local, java.lang.String remote) throws java.io.IOException, FtpCException
local
- local file name of the file to be retrievedremote
- file name on the server of the file to be retrievedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void get(java.io.OutputStream oStream, java.lang.String remote) throws java.io.IOException, FtpCException
oStream
- output stream for the retrieved fileremote
- file name on the server of the file to be retrievedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void delete(java.lang.String fileName) throws java.io.IOException, FtpCException
fileName
- file name of the file to be deletedIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public java.lang.String[] dir(java.lang.String dir) throws java.io.IOException, FtpCException
dir
- name of the directoryIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public java.lang.String[] dir(java.lang.String dir, java.lang.String attr) throws java.io.IOException, FtpCException
dir
- name of the directoryattr
- ls command like attributesIOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public void setBin() throws java.io.IOException, FtpCException
IOException
- thrown by external used classesFtpCException
- thrown whea non valid reply has been returned by the FTP server or when not connected.java.io.IOException
FtpCException
public java.lang.String getVersion()