Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Member Functions | Static Package Functions | Package Attributes
rene.util.ftp.FTP Class Reference

An FTP protocol handler. More...

Collaboration diagram for rene.util.ftp.FTP:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FTP (String server, int port)
 Just denote the server and port (default is 21).
 FTP (String server)
void open () throws IOException,UnknownHostException
 Open the connection to the server, getting the control data streams.
void open (String user, String password) throws IOException,UnknownHostException
 Open the server and connect as user with the password.
void close () throws IOException
 Close the connection to the server and the control data streams.
int getreply () throws IOException
 Wait for reply from the server.
boolean command (String s) throws IOException
 Send a command to the server and wait for a direct reply.
Answer answer ()
 This returns the Answer to the previous command.
void send (String s) throws IOException
 Send a command to the server.
Socket passive () throws IOException,UnknownHostException, NumberFormatException
 Tell the server to wait for a data connection on a port of his discretion.
InputStream getFile (String file) throws IOException,UnknownHostException
 Get an input stream to the file.
InputStream getDir (String path) throws IOException,UnknownHostException
 Get an input stream to the list.
InputStream getLs (String path) throws IOException,UnknownHostException
 Get an input stream to the list.
void getClose () throws IOException
 Close the data socket after a get command and wait for the transfer complete message.
OutputStream putFile (String file) throws IOException,UnknownHostException
 Get an output stream to the file.
void putClose () throws IOException
 Close the date socket after a put command and wait for the transfer complete message.
void changeDirectory (String dir) throws IOException
 Cange the directory to the specified one.
Vector getDirectory (String dir) throws IOException
Vector getCurrentDirectory () throws IOException

Static Public Member Functions

static void main (String args[])

Static Package Functions

static void testGet (InputStream in) throws IOException
static void testPut (OutputStream out) throws IOException

Package Attributes

String Server
int Port
Socket S
BufferedReader In
PrintWriter Out
Answer A
Socket DSocket

Detailed Description

An FTP protocol handler.

See main for an example.

Definition at line 11 of file FTP.java.


Constructor & Destructor Documentation

rene.util.ftp.FTP.FTP ( String  server,
int  port 
) [inline]

Just denote the server and port (default is 21).

The connection has to be opened and closed!

Definition at line 23 of file FTP.java.

       {      Server=server; Port=port;
       }

Here is the caller graph for this function:

rene.util.ftp.FTP.FTP ( String  server) [inline]

Definition at line 27 of file FTP.java.

       {      this(server,21);
       }

Member Function Documentation

This returns the Answer to the previous command.

The meanings of Answer.code() are:

  • 1xx - Another reply will follow
  • 2xx - The answer is positive
  • 3xx - The answer is positive, but needs more action
  • 4xx - The answer is negative, but one can try again
  • 5xx - The answer is negative

A.text() will contain the text, the server sent. In case of multiline text, this will be separated by
.

Definition at line 101 of file FTP.java.

       {      return A; 
       }
void rene.util.ftp.FTP.changeDirectory ( String  dir) throws IOException [inline]

Cange the directory to the specified one.

Definition at line 233 of file FTP.java.

       {      if (!command("CWD "+dir))
                     throw new IOException("Directory change failed.");
       }

Here is the call graph for this function:

void rene.util.ftp.FTP.close ( ) throws IOException [inline]

Close the connection to the server and the control data streams.

Definition at line 59 of file FTP.java.

       {      send("QUIT");
              In.close();
              Out.close();
              S.close();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean rene.util.ftp.FTP.command ( String  s) throws IOException [inline]

Send a command to the server and wait for a direct reply.

This will set the Answer field for checking.

Returns:
true if the command succeeded immediately.

Definition at line 83 of file FTP.java.

       {      send(s);
              return (getreply()/100<4);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void rene.util.ftp.FTP.getClose ( ) throws IOException [inline]

Close the data socket after a get command and wait for the transfer complete message.

Definition at line 189 of file FTP.java.

       {      DSocket.close();
              while (true)
              {      getreply();
                     if (A.code()==226) return;
                     if (A.code()>=400)
                            throw new IOException("Put failed.");
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector rene.util.ftp.FTP.getCurrentDirectory ( ) throws IOException [inline]

Definition at line 259 of file FTP.java.

       {      return getDirectory(".");
       }

Here is the call graph for this function:

Here is the caller graph for this function:

InputStream rene.util.ftp.FTP.getDir ( String  path) throws IOException,UnknownHostException [inline]

Get an input stream to the list.

getClose() must be called!

Definition at line 157 of file FTP.java.

       {      DSocket=passive();
              if (!command("TYPE A"))
                     throw new IOException("Type A not supported?");
              if (!path.equals("")) send("LIST "+path);
              else send("LIST");
              getreply();
              if (A.code()/100>=4) throw new IOException("ls failed.");
              return DSocket.getInputStream();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector rene.util.ftp.FTP.getDirectory ( String  dir) throws IOException [inline]

Definition at line 239 of file FTP.java.

       {      Vector v=new Vector();
              try
              {      BufferedReader In=new BufferedReader(
                            new InputStreamReader(getDir(dir)));
                     while (true)
                     {      String s=In.readLine();
                            if (s==null) break;
                            v.addElement(s);
                     }
                     In.close();
              }
              catch (Exception e)
              {      throw new IOException("Directory list failed.");
              }
              getClose();
              return v;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

InputStream rene.util.ftp.FTP.getFile ( String  file) throws IOException,UnknownHostException [inline]

Get an input stream to the file.

getClose() must be called!

Definition at line 142 of file FTP.java.

       {      DSocket=passive();
              if (!command("TYPE I"))
                     throw new IOException("Type I not supported?");
              send("RETR "+file);
              getreply();
              if (A.code()/100>=4) throw new IOException("Get failed.");
              return DSocket.getInputStream();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

InputStream rene.util.ftp.FTP.getLs ( String  path) throws IOException,UnknownHostException [inline]

Get an input stream to the list.

getClose() must be called!

Definition at line 173 of file FTP.java.

       {      DSocket=passive();
              if (!command("TYPE A"))
                     throw new IOException("Type A not supported?");
              if (!path.equals("")) send("NLST "+path);
              else send("NLST");
              getreply();
              if (A.code()/100>=4) throw new IOException("ls failed.");
              return DSocket.getInputStream();
       }

Here is the call graph for this function:

int rene.util.ftp.FTP.getreply ( ) throws IOException [inline]

Wait for reply from the server.

Returns:
the reply code (1xx,2xx,3xx are OK).

Definition at line 70 of file FTP.java.

       {      A=new Answer();
              A.get(In);
              //System.out.println(A.code());
              //System.out.println(A.text());
              return A.code();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static void rene.util.ftp.FTP.main ( String  args[]) [inline, static]

Definition at line 264 of file FTP.java.

       {      try
              {      //FTP ftp=new FTP("mathsrv.ku-eichstaett.de");
                     //ftp.open("","");
                     FTP ftp=new FTP("localhost");
                     ftp.open("","");
                     testPut(ftp.putFile("test"));
                     ftp.putClose();
                     testGet(ftp.getFile("test"));
                     ftp.getClose();
                     Enumeration e=ftp.getCurrentDirectory().elements();
                     while (e.hasMoreElements())
                     {      System.out.println((String)e.nextElement());
                     }
                     ftp.close();
              }
              catch (Exception e)
              {      System.out.println(e);
              }      
       }

Here is the call graph for this function:

void rene.util.ftp.FTP.open ( ) throws IOException,UnknownHostException [inline]

Open the connection to the server, getting the control data streams.

Definition at line 35 of file FTP.java.

       {      S=new Socket(Server,Port);
              In=new BufferedReader(new InputStreamReader(
                     new DataInputStream(S.getInputStream())));
              Out=new PrintWriter(S.getOutputStream());
              if (getreply()/100!=2)
                     throw new IOException("Illegal reply.");
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void rene.util.ftp.FTP.open ( String  user,
String  password 
) throws IOException,UnknownHostException [inline]

Open the server and connect as user with the password.

Definition at line 47 of file FTP.java.

       {      open();
              if (!command("USER "+user))
                     throw new IOException("User not accepted.");
              if (!command("PASS "+password))
                     throw new IOException("Wrong Password");
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Socket rene.util.ftp.FTP.passive ( ) throws IOException,UnknownHostException, NumberFormatException [inline]

Tell the server to wait for a data connection on a port of his discretion.

The return of the server is scanned for the IP and the port and a Socket is generated.

Returns:
Socket for the data connection to the server

Definition at line 118 of file FTP.java.

       {      if (!command("PASV"))
                     throw new IOException("Passive mode not supported.");
              StringTokenizer p=new StringTokenizer(A.text(),"(,)");
              if (!p.hasMoreTokens())
                     throw new IOException("Wrong answer from server.");
              else p.nextToken();
              int N[]=new int[4];
              for (int i=0; i<4; i++)
              {      N[i]=Integer.parseInt(p.nextToken());
              }
              int k=Integer.parseInt(p.nextToken());
              int P=k*256+Integer.parseInt(p.nextToken());
              String server=N[0]+"."+N[1]+"."+N[2]+"."+N[3];
              return new Socket(server,P);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void rene.util.ftp.FTP.putClose ( ) throws IOException [inline]

Close the date socket after a put command and wait for the transfer complete message.

Definition at line 219 of file FTP.java.

       {      DSocket.close();
              while (true)
              {      getreply();
                     if (A.code()==226) return;
                     if (A.code()>=400)
                            throw new IOException("Put failed.");
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

OutputStream rene.util.ftp.FTP.putFile ( String  file) throws IOException,UnknownHostException [inline]

Get an output stream to the file.

putClose() must be called!

Definition at line 204 of file FTP.java.

       {      DSocket=passive();
              if (!command("TYPE I"))
                     throw new IOException("Type I not supported?");
              send("STOR "+file);
              getreply();
              if (A.code()/100>=4) throw new IOException("Put failed.");
              return DSocket.getOutputStream();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void rene.util.ftp.FTP.send ( String  s) throws IOException [inline]

Send a command to the server.

Definition at line 108 of file FTP.java.

       {      Out.println(s); Out.flush();
       }

Here is the caller graph for this function:

static void rene.util.ftp.FTP.testGet ( InputStream  in) throws IOException [inline, static, package]

Definition at line 285 of file FTP.java.

       {      BufferedReader In=new BufferedReader(
                     new InputStreamReader(in));
              while (true)
              {      String s=In.readLine();
                     if (s==null) break;
                     System.out.println(s);
              }
              In.close();
       }

Here is the caller graph for this function:

static void rene.util.ftp.FTP.testPut ( OutputStream  out) throws IOException [inline, static, package]

Definition at line 297 of file FTP.java.

       {      PrintWriter Out=new PrintWriter(out);
              Out.println("Erste Zeile: Test");
              Out.println("Zweite Zeile: Test");
              Out.print("Dritte Zeile");
              Out.flush();
              Out.close();
       }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 17 of file FTP.java.

Socket rene.util.ftp.FTP.DSocket [package]

Definition at line 136 of file FTP.java.

BufferedReader rene.util.ftp.FTP.In [package]

Definition at line 15 of file FTP.java.

PrintWriter rene.util.ftp.FTP.Out [package]

Definition at line 16 of file FTP.java.

int rene.util.ftp.FTP.Port [package]

Definition at line 13 of file FTP.java.

Socket rene.util.ftp.FTP.S [package]

Definition at line 14 of file FTP.java.

String rene.util.ftp.FTP.Server [package]

Definition at line 12 of file FTP.java.


The documentation for this class was generated from the following file: