cz.dhl.ftp
Class Ftp

java.lang.Object
  extended bycz.dhl.ftp.Ftp
All Implemented Interfaces:
CoSource

public final class Ftp
extends java.lang.Object
implements CoSource

Allows connect to FTP server and maintains control connection.

Version:
0.72 08/10/2003
Author:
Bea Petrovicova

Field Summary
static int PORT
          Default FTP port number.
 
Constructor Summary
Ftp()
          Creates a new Ftp instance.
 
Method Summary
 void abort()
          Abort connection.
 boolean cd(java.lang.String directory)
          Change server working directory.
 boolean cdup()
          Change server directory to parent.
 boolean command(java.lang.String commandline)
          Enter custom server command.
 boolean connect(FtpConnect connect)
          Connect & login.
 boolean connect(java.lang.String server, int port)
          Connect to server, open control connection.
 void disconnect()
          Disconnect from server, close control connection.
 FtpContext getContext()
          Return FtpContext object.
 java.lang.String host()
          Returns server host name.
 boolean chmod(java.lang.String filename, java.lang.String mode)
          Change server file mode.
 boolean isConnected()
          Tests connection.
 boolean login(java.lang.String username, java.lang.String password)
          Log in to server, enter username and password.
 boolean mkdir(java.lang.String directory)
          Make server working directory.
 boolean mv(java.lang.String oldfilename, java.lang.String newfilename)
          Rename server file.
 java.lang.String pwd()
          Print server working directory.
 boolean rm(java.lang.String filename)
          Delete server file.
 boolean rmdir(java.lang.String directory)
          Remove server directory.
 java.lang.String syst()
          Print server system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT

public static final int PORT
Default FTP port number.

See Also:
Constant Field Values
Constructor Detail

Ftp

public Ftp()
Creates a new Ftp instance.

Method Detail

abort

public void abort()
Abort connection.


cd

public boolean cd(java.lang.String directory)
Change server working directory.

CWD - change working directory.

This command allows the user to work with a different directory or dataset for file storage or retrieval without altering his login or accounting information. Transfer parameters are similarly unchanged. The argument is a pathname specifying a directory or other system dependent file group designator.

Parameters:
directory - Name of new working directory.

Returns:
True on success.

cdup

public boolean cdup()
Change server directory to parent.

CDUP - change up.

This command is a special case of CWD, and is included to simplify the implementation of programs for transferring directory trees between operating systems having different File Transfer Protocol syntaxes for naming the parent directory.

Returns:
True on success.

command

public boolean command(java.lang.String commandline)
Enter custom server command.

Not all FTP commands are accepted. Exceptions are especially commands for transferring files and altering way data transfer is performed.

Returns:
True on success.

connect

public boolean connect(FtpConnect connect)
                throws java.io.IOException
Connect & login.

Parameters:
connect - Connection details.
Returns:
port Server FTP port number normally 21.
Throws:
java.io.IOException

connect

public boolean connect(java.lang.String server,
                       int port)
                throws java.io.IOException
Connect to server, open control connection.

Parameters:
server - Server DNS server name or dot delimited IP address.
Returns:
port Server FTP port number normally 21.
Throws:
java.io.IOException

disconnect

public void disconnect()
Disconnect from server, close control connection.


getContext

public FtpContext getContext()
Return FtpContext object.

Returns:
context
See Also:
FtpContext

host

public java.lang.String host()
                      throws java.io.IOException
Returns server host name.

Returns:
Server host name on success.
Throws:
java.io.IOException

chmod

public boolean chmod(java.lang.String filename,
                     java.lang.String mode)
Change server file mode.

Parameters:
filename - Name of file to change mode.
mode - Mode is UNIX "777" format string.
Returns:
True on success.

isConnected

public boolean isConnected()
Tests connection.


login

public boolean login(java.lang.String username,
                     java.lang.String password)
              throws java.io.IOException
Log in to server, enter username and password.

USER - user name.

The argument field is a Telnet string identifying the user. The user identification is that does require the server for access to its file system. This command will normally be the first command transmitted by the user after the control connections are made (some servers may require this). Additional identification information in the form of a password and/or an account command may also be required by some servers. Servers may allow a new USER command to be entered at any point in order to change the access control and/or accounting information. This has the effect of flushing any user, password, and account information already supplied and beginning the login sequence again. All transfer parameters are unchanged and any file transfer in progress is completed under the old access control parameters.

PASS - password.

The argument field is a Telnet string specifying the user's password. This command must be immediately preceded by the user name command, and, for some sites, completes the user's identification for access control. Since password information is quite sensitive, it is desirable in general to "mask" it or suppress typeout. It appears that the server has no foolproof way to achieve this. It is therefore the responsibility of the user-FTP process to hide the sensitive password information.

Parameters:
username - Server account username.
password - Server account password.
Returns:
True on success.
Throws:
java.io.IOException

mkdir

public boolean mkdir(java.lang.String directory)
Make server working directory.

MKD - make directory.

This command causes the directory specified in the pathname to be created as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).

Parameters:
directory - Name of newly created directory.
Returns:
True on success.

mv

public boolean mv(java.lang.String oldfilename,
                  java.lang.String newfilename)
Rename server file.

RNFR - rename from.

This command specifies the old pathname of the file, which is to be renamed. This command must be immediately followed by a "rename to" command specifying the new file pathname.

RNTO - rename to.

This command specifies the new pathname of the file specified in the immediately preceding "rename from" command. Together the two commands cause a file to be renamed.

Parameters:
oldfilename - Old name of file.
newfilename - New name of file.
Returns:
True on success.

pwd

public java.lang.String pwd()
                     throws java.io.IOException
Print server working directory.

PWD - print working directory.

This command causes the name of the current working directory to be returned in the reply.

Returns:
Current working directory.
Throws:
java.io.IOException

rm

public boolean rm(java.lang.String filename)
Delete server file.

DELE - delete.

This command causes the file specified in the pathname to be deleted at the server site. If an extra level of protection is desired (such as the query, "Do you really wish to delete?"), it should be provided by the user-FTP process.

Parameters:
filename - Name of file to be deleted.
Returns:
True on success.

rmdir

public boolean rmdir(java.lang.String directory)
Remove server directory.

RMD - remove directory.

This command causes the directory specified in the pathname to be removed as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).

Parameters:
directory - Name of directory to be removed.
Returns:
True on success.

syst

public java.lang.String syst()
                      throws java.io.IOException
Print server system.

SYST - print server system.

This command causes the name name and version of the server system to be returned in the reply.

Returns:
Server system.
Throws:
java.io.IOException


Available from sourceforge http://sourceforge.net/projects/jvftp under the terms of GNU Lesser General Public License (LGPL).