|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.compomics.util.io.FTP
public class FTP
This class was modified from a source found on the net (java.sun.com, search in developer section on 'FtpProtocolException PORT').
Field Summary | |
---|---|
String |
command
The last command issued. |
protected Socket |
controlSocket
Socket for communicating commands with the server. |
static int |
FILE_GET
Pre-defined state. |
static int |
FILE_PUT
Pre-defined state. |
static int |
FTP_PORT
FTP port to use for connection. |
protected String |
m_strDestination
|
protected String |
m_strSource
|
InputStream |
serverInput
Buffered stream for reading replies from server. |
PrintWriter |
serverOutput
Stream for printing to the server. |
protected Vector |
serverResponse
Array of strings (usually 1 entry) for the last reply from the server. |
protected String |
strFileNameAndPath
String to hold the file we are up/downloading |
String |
welcomeMsg
Welcome message from the server, if any. |
Constructor Summary | |
---|---|
FTP(String host)
Constructor for an FTP client connected to host host. |
|
FTP(String host,
int port)
Constructor for an FTP client connected to host host and port port. |
Method Summary | |
---|---|
void |
abort()
Send Abort command. |
BufferedWriter |
appendAscii(String filename)
APPEND (with create) to a file to the FTP server in Ascii mode. |
BufferedOutputStream |
appendBinary(String filename)
APPEND (with create) to a file to the FTP server in Binary mode. |
void |
ascii()
Set transfer type to 'A' (ascii transfer). |
void |
binary()
Set transfer type to 'I' (binary transfer). |
void |
cd(String remoteDirectory)
CD to a specific directory on a remote FTP server. |
void |
cdup()
Go up one directory on remote system. |
void |
closeServer()
Issue the QUIT command to the FTP server and close the connection. |
void |
cwd(String remoteDirectory)
Change working directory to a specific directory on a remote FTP server. |
void |
delete(String aFile)
Delete the specified file from the ftp server file system. |
BufferedReader |
dir()
Folder-list files on a remote FTP server. |
BufferedReader |
getAscii(String filename)
GET a file from the FTP server in Ascii mode. |
BufferedInputStream |
getBinary(String filename)
GET a file from the FTP server in Binary mode. |
String |
getDestinationFile()
This method reports on the destinationfile currently used in transfer. |
String |
getResponseString()
Returns all server response strings. |
String |
getResponseStringNoReset()
This method allows the caller to read the response strings from the server, without resetting the internal buffer (and thus not clearing the messages read by this messages). |
String |
getSourceFile()
This method reports on the sourcefile currently used in transfer. |
protected int |
issueCommand(String cmd)
This method allows the caller to issue a command to the server. |
protected void |
issueCommandCheck(String cmd)
This method will issue the specified command and throw an exception whenever the reply is not equal to success! |
BufferedReader |
list()
LIST files on a remote FTP server. |
void |
login(String user)
Login user to a host with username user and no password such as HP server which uses the form " |
void |
login(String user,
String password)
Login user to a host with username user and password password. |
BufferedReader |
ls()
Folder-list files on a remote FTP server. |
void |
mkdir(String aDir)
Create a directory on the remote system |
BufferedReader |
nlist()
NLIST files on a remote FTP server |
protected Socket |
openDataConnection(String cmd)
This method will set up the networking for client-server data transfer and it will send the specified command to the server. |
void |
openServer(String host)
open a FTP connection to host host. |
void |
openServer(String host,
int port)
Open an FTP connection to host host on port port. |
BufferedWriter |
putAscii(String filename)
PUT a file on the FTP server in Ascii mode. |
BufferedOutputStream |
putBinary(String filename)
PUT a file to the FTP server in Binary mode |
void |
pwd()
Get the name of the present working directory on the ftp server file system. |
protected int |
readReply()
This method attempts to read a reply from the FTP server. |
int |
readServerResponse()
This method allows the caller to capture the serverresponse. |
void |
rename(String oldFile,
String newFile)
Rename a file on the remote server. |
void |
rmdir(String aDir)
Delete the specified directory from the ftp server file system. |
void |
sendServer(String cmd)
Sends command cmd to the server. |
boolean |
serverIsOpen()
Return server connection status |
void |
setDestinationFile(String strDestinationFile)
This method allows the specification of the destinationfile. |
void |
SetFileMode(int nMode)
This method sets the file transfer mode. |
void |
setFilename(String strFile)
This method sets the name of the file to up- or download. |
void |
setPassive(boolean mode)
Set Passive mode Trasfers. |
void |
setSourceFile(String strSourceFile)
This method allows to set the source for the file that is to be transferred. |
void |
site(String params)
Site Command |
void |
syst()
Retrieve the system type from the remote server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int FTP_PORT
public static int FILE_GET
public static int FILE_PUT
public String command
public String welcomeMsg
protected Vector serverResponse
protected Socket controlSocket
public PrintWriter serverOutput
public InputStream serverInput
protected String strFileNameAndPath
protected String m_strSource
protected String m_strDestination
Constructor Detail |
---|
public FTP(String host) throws IOException
host
- String with the hostname (or IP) to connect to.
IOException
- whenever a connection could not be made.public FTP(String host, int port) throws IOException
host
- String with the hostname (or IP) to connect to.port
- int with the portnumber for the host FTP server.
IOException
- whenever a connection could not be made.Method Detail |
---|
public void setFilename(String strFile)
strFile
- String with the filename.public void setSourceFile(String strSourceFile)
strSourceFile
- String with the sourec for the file to be
transferred.public void setDestinationFile(String strDestinationFile)
strDestinationFile
- String with the destination file.public String getSourceFile()
public String getDestinationFile()
public boolean serverIsOpen()
public void setPassive(boolean mode)
mode
- boolean to indicate whether passive mode
should be used.public int readServerResponse() throws IOException
IOException
public void sendServer(String cmd)
cmd
- String with the command to send.public String getResponseString()
public String getResponseStringNoReset()
public void closeServer() throws IOException
IOException
protected int issueCommand(String cmd) throws IOException
cmd
- String with the command to issue.
IOException
- when the connection with the server failed.protected void issueCommandCheck(String cmd) throws IOException
cmd
- String with the command to issue (and verify the response for)
IOException
- when the connection failed OR FtpProtocolException when the
command was not understood by the server.protected int readReply() throws IOException
IOException
- whenever the reply could not be read.protected Socket openDataConnection(String cmd) throws IOException
cmd
- String with the command to issue.
IOException
- whenever communications could not be established.public void openServer(String host) throws IOException, UnknownHostException
host
- String with the hostname (or IP) to connect to.
IOException
- whenever connection could not be established.
UnknownHostException
- when the hostname cannot be resolved.public void openServer(String host, int port) throws IOException, UnknownHostException
host
- String with the hostname (or IP) of the FTP server.port
- int with the portnumber the FTP server is listening on.
IOException
- whenever connection could not be established.
UnknownHostException
- when the hostname cannot be resolved.public void login(String user, String password) throws IOException
user
- String with the username to use.password
- String with the password to use (passwords are sent in plain text in FTP!)
IOException
public void login(String user) throws IOException
user
- String with the username (and possibly coded information such as password).
IOException
public BufferedReader getAscii(String filename) throws IOException
filename
- String with the filename to get from the server.
IOException
- whenever the file could not be read.public BufferedInputStream getBinary(String filename) throws IOException
filename
- String with the filename to get from the server.
IOException
- whenever the file could not be read.public BufferedWriter putAscii(String filename) throws IOException
filename
- String with the filename to put on the server.
IOException
- whenever the file could not be sent.public BufferedOutputStream putBinary(String filename) throws IOException
filename
- String with the filename to put on the server.
IOException
- whenever the file could not be sent.public BufferedWriter appendAscii(String filename) throws IOException
filename
- String with the name of the file to append to.
IOException
- whenever the writer fails.public BufferedOutputStream appendBinary(String filename) throws IOException
filename
- String with the name of the file to append to.
IOException
- whenever the writer fails.public BufferedReader nlist() throws IOException
IOException
- whenever the listing failed.public BufferedReader list() throws IOException
IOException
- whenever the listing failed.public BufferedReader ls() throws IOException
IOException
- whenever the listing failed.public BufferedReader dir() throws IOException
IOException
- whenever the listing failed.public void cd(String remoteDirectory) throws IOException
remoteDirectory
- String with the directory to CD to.
IOException
- whenever the CD failed.public void cwd(String remoteDirectory) throws IOException
remoteDirectory
- String with the directory to CWD to.
IOException
- whenever the CWD failed.public void rename(String oldFile, String newFile) throws IOException
oldFile
- String with the original filename for the file to rename.newFile
- String with the filename to rename the file to.
IOException
- when the renaming failed.public void site(String params) throws IOException
params
- String with the parameters for the SITE command.
IOException
- when the SITE command failed.public void binary() throws IOException
IOException
- when the binary mode could not be set up.public void ascii() throws IOException
IOException
- when the ASCII mode could not be set up.public void abort() throws IOException
IOException
- when the cancellation could not be
executed.public void cdup() throws IOException
IOException
- when the CDUP failed.public void mkdir(String aDir) throws IOException
aDir
- String with the name for the directory to be created.
IOException
- when the directory could not be created.public void rmdir(String aDir) throws IOException
aDir
- String with the directory to delete.
IOException
- when the deletion did not succeed.public void delete(String aFile) throws IOException
aFile
- String with the filename for the file to delete.
IOException
- when the deletion did not succeed.public void pwd() throws IOException
IOException
- whenever the server did not report on the pwd.public void syst() throws IOException
IOException
- whenever the system type could not be determined.public void SetFileMode(int nMode)
nMode
- int with the mode (either FILE_GET for retrieval,
or any other int for sending a file).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |