Modifier and Type | Field and Description |
---|---|
private FtpContext |
context |
(package private) FtpControlSocket |
control |
static int |
PORT
Default FTP port number.
|
Constructor and Description |
---|
Ftp()
Creates a new Ftp instance.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Abort connection.
|
boolean |
cd(String directory)
Change server working directory.
|
boolean |
cdup()
Change server directory to parent.
|
boolean |
chmod(String filename,
String mode)
Change server file mode.
|
boolean |
command(String commandline)
Enter custom server command.
|
boolean |
connect(FtpConnect connect)
Connect & login.
|
boolean |
connect(String server,
int port)
Connect to server, open control connection.
|
void |
disconnect()
Disconnect from server, close control connection.
|
FtpContext |
getContext()
Return FtpContext object.
|
String |
host()
Returns server host name.
|
boolean |
isConnected()
Tests connection.
|
boolean |
login(String username,
String password)
Log in to server, enter username and password.
|
boolean |
mkdir(String directory)
Make server working directory.
|
boolean |
mv(String oldfilename,
String newfilename)
Rename server file.
|
(package private) void |
printerr(Exception exception) |
(package private) void |
printlog(String message) |
String |
pwd()
Print server working directory.
|
boolean |
rm(String filename)
Delete server file.
|
boolean |
rmdir(String directory)
Remove server directory.
|
String |
syst()
Print server system.
|
public static final int PORT
private FtpContext context
FtpControlSocket control
public Ftp()
public boolean connect(FtpConnect connect) throws IOException
connect
- Connection details.IOException
public boolean connect(String server, int port) throws IOException
server
- Server DNS server name or dot delimited IP address.IOException
public void disconnect()
public void abort()
public boolean login(String username, String password) throws IOException
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.
username
- Server account username.password
- Server account password.IOException
public String host() throws IOException
IOException
public boolean command(String commandline)
Not all FTP commands are accepted. Exceptions are especially commands for transferring files and altering way data transfer is performed.
public boolean rmdir(String 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).
directory
- Name of directory to be removed.public boolean mkdir(String 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).
directory
- Name of newly created directory.public String pwd() throws IOException
PWD - print working directory.
This command causes the name of the current working directory to be returned in the reply.
IOException
public String syst() throws IOException
SYST - print server system.
This command causes the name name and version of the server system to be returned in the reply.
IOException
public boolean cd(String 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.
directory
- Name of new working directory.public boolean cdup()
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.
public boolean rm(String filename)
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.
filename
- Name of file to be deleted.public boolean mv(String oldfilename, String newfilename)
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.
oldfilename
- Old name of file.newfilename
- New name of file.public boolean chmod(String filename, String mode)
filename
- Name of file to change mode.mode
- Mode is UNIX "777" format string.public boolean isConnected()
public FtpContext getContext()
FtpContext
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses