public class FTPClient extends Object
Constructor and Description |
---|
FTPClient() |
Modifier and Type | Method and Description |
---|---|
boolean |
auth()
Establish a secure connection.
|
String |
cdup()
Issues CDUP command.
|
void |
close()
Closes the FTP connection.
|
String |
command(String cmd)
Issues supplied command and logs the response.
|
boolean |
connect(String server)
Establishes the FTP connection.
|
String |
cwd(String dir)
Change working directory
|
boolean |
delete(String file)
Deletes the given file on the remote host.
|
String |
dir(boolean nlst)
Obtain the directory.
|
void |
enableLog(boolean enable)
Enables the cumulative log.
|
String |
feat()
Issues FEAT command
|
String |
getLog()
Obtains the cumulative log content.
|
boolean |
isConnected()
Check if client connected to server
|
String |
list(boolean nlst)
Issues the LIST command.
|
boolean |
login(String user,
String pass)
Perform user login.
|
String |
mdtm(String file)
Returns the last-modified time of the given file on the remote host.
|
String |
mfmt(String file,
String filedate)
Set remote file last modified timestamp
|
boolean |
mkdir(String dir)
Creates the named directory on the remote host.
|
String |
mlsd(String dir)
Return standardized facts for contents of the directory.
|
String |
mlst(String file)
Return standardized facts about a single item.
|
String |
noop()
Issues NOOP command
|
FileEntry[] |
parseDir(String listing)
Returns an array of FileEntry containing the details for each file or folder in the directory.
|
int[] |
pasv()
Issue PASV command and retrieve connect parameters
|
String |
port(InetAddress addr,
int portnum)
Issue PORT command.
|
String |
pwd()
Issues PWD command.
|
String |
quit()
Issues QUIT command
|
boolean |
rename(String from,
String to)
Renames a remote file.
|
void |
resetLog()
Resets the cumulative log.
|
int |
responseCode(String response)
Returns the response code in the reply.
|
int |
responsePurpose(String response)
Returns the purpose of the reply.
|
int |
responseStatus(String response)
Returns the status of the reply.
|
boolean |
retrieve(String dstfile,
String remotefile)
Transfers file content from a remote host.
|
boolean |
rmdir(String dir)
Deletes the named directory on the remote host.
|
void |
setPassive(boolean mode)
Used to set passive or active mode.
|
void |
setSoTimeout(int to)
Sets timeout in milliseconds used during data transfers.
|
int |
size(String file)
Returns the size of the remote file.
|
boolean |
store(String srcfile,
String remotefile)
Transfers file content to a remote host.
|
String |
syst()
Issues SYST command
|
String |
type(String stype)
Issues TYPE command with the provided parameter.
|
public boolean connect(String server)
server
- URL or IP address of the target FTP Serverpublic void close()
public void setSoTimeout(int to)
to
- timeout in millisecondspublic void setPassive(boolean mode)
mode
- true if passive transfers are to be used.public void resetLog()
public void enableLog(boolean enable)
enable
- set true if logging is to be enabledpublic String getLog()
public boolean login(String user, String pass)
user
- usernamepass
- passwordpublic boolean auth()
public String cdup()
public String cwd(String dir)
dir
- string containing the directorypublic boolean delete(String file)
file
- remote filenamepublic String feat()
public String list(boolean nlst)
nlst
- set true to return list of files onlypublic String mdtm(String file)
file
- name of the remote filepublic String mfmt(String file, String filedate)
file
- filename on the remote systemfiledate
- timestamp in YYYYMMDDHHMMSS formatpublic boolean mkdir(String dir)
dir
- directory namepublic String mlsd(String dir)
dir
- remote directorypublic String mlst(String file)
file
- the item of interest (current directory if absent).public String noop()
public String pwd()
public String port(InetAddress addr, int portnum)
addr
- local IP addressportnum
- local port numberpublic String quit()
public boolean rename(String from, String to)
from
- remote file to be renamedto
- new name for the filepublic boolean rmdir(String dir)
dir
- directory namepublic int size(String file)
file
- the remote filenamepublic String syst()
public String type(String stype)
stype
- ASCII type character ("I: for binary)public int[] pasv()
public String dir(boolean nlst)
nlst
- set true to return list of filenames onlypublic FileEntry[] parseDir(String listing)
listing
- The directory listing textpublic boolean retrieve(String dstfile, String remotefile)
dstfile
- destination file on the local systemremotefile
- source filename on the remote hostpublic boolean store(String srcfile, String remotefile)
srcfile
- source file on the local systemremotefile
- destination filename on the remote hostpublic String command(String cmd)
cmd
- string containing the complete command.public int responseCode(String response)
response
- the response string returned by the FTP Serverpublic int responseStatus(String response)
response
- the response string returned by the FTP Serverpublic int responsePurpose(String response)
response
- the response string returned by the FTP Serverpublic boolean isConnected()