A simple standalone FTP client.
| Methods |
| static FtpClient |
open(String url)
Open an FTP connection.
|
| static FtpClient |
open(String url) throws IOException
Open an FTP connection.
Parameters:
url - the FTP URL
Returns:
the ftp client object
|
| void |
changeDirectoryUp()
Change to the parent directory (CDUP).
|
| void |
changeDirectoryUp() throws IOException
Change to the parent directory (CDUP).
|
| void |
changeWorkingDirectory(String dir)
Change the working directory (CWD).
|
| void |
changeWorkingDirectory(String dir) throws IOException
Change the working directory (CWD).
Parameters:
dir - the new directory
|
| void |
close()
Close the connection (QUIT).
|
| void |
close() throws IOException
Close the connection (QUIT).
|
| void |
delete(String fileName)
Delete a file (DELE).
|
| void |
delete(String fileName) throws IOException
Delete a file (DELE).
Parameters:
fileName - the name of the file to delete
|
| boolean |
exists(String dir, String name)
Check if a file exists on the FTP server.
|
| boolean |
exists(String dir, String name) throws IOException
Check if a file exists on the FTP server.
Parameters:
dir - the directory
name - the directory or file name
Returns:
true if it exists
|
| String |
list(String dir)
Get the directory listing (LIST).
|
| String |
list(String dir) throws IOException
Get the directory listing (LIST).
Parameters:
dir - the directory
Returns:
the listing
|
| File[] |
listFiles(String dir)
List the files on the FTP server.
|
| File[] |
listFiles(String dir) throws IOException
List the files on the FTP server.
Parameters:
dir - the directory
Returns:
the list of files
|
| void |
login(String userName, String password)
Login to this FTP server (USER, PASS, SYST, SITE, STRU F, TYPE I).
|
| void |
login(String userName, String password) throws IOException
Login to this FTP server (USER, PASS, SYST, SITE, STRU F, TYPE I).
Parameters:
userName - the user name
password - the password
|
| void |
makeDirectory(String dir)
Create a directory (MKD).
|
| void |
makeDirectory(String dir) throws IOException
Create a directory (MKD).
Parameters:
dir - the directory to create
|
| void |
mode(String mode)
Change the transfer mode (MODE).
|
| void |
mode(String mode) throws IOException
Change the transfer mode (MODE).
Parameters:
mode - the mode
|
| void |
modificationTime(String fileName)
Change the modified time of a file (MDTM).
|
| void |
modificationTime(String fileName) throws IOException
Change the modified time of a file (MDTM).
Parameters:
fileName - the file name
|
| String |
nameList(String dir)
Get the directory listing (NLST).
|
| String |
nameList(String dir) throws IOException
Get the directory listing (NLST).
Parameters:
dir - the directory
Returns:
the listing
|
| void |
noOperation()
Issue a no-operation statement (NOOP).
|
| void |
noOperation() throws IOException
Issue a no-operation statement (NOOP).
|
| String |
printWorkingDirectory()
Print the working directory (PWD).
|
| String |
printWorkingDirectory() throws IOException
Print the working directory (PWD).
Returns:
the working directory
|
| void |
removeDirectory(String dir)
Remove a directory (RMD).
|
| void |
removeDirectory(String dir) throws IOException
Remove a directory (RMD).
Parameters:
dir - the directory to remove
|
| void |
removeDirectoryRecursive(String dir)
Remove all files and directory in a directory, and then delete the
directory itself.
|
| void |
removeDirectoryRecursive(String dir) throws IOException
Remove all files and directory in a directory, and then delete the
directory itself.
Parameters:
dir - the directory to remove
|
| void |
rename(String fromFileName, String toFileName)
Rename a file (RNFR / RNTO).
|
| void |
rename(String fromFileName, String toFileName) throws IOException
Rename a file (RNFR / RNTO).
Parameters:
fromFileName - the old file name
toFileName - the new file name
|
| byte[] |
retrieve(String fileName)
Read a file.
|
| byte[] |
retrieve(String fileName) throws IOException
Read a file.
Parameters:
fileName - the file name
Returns:
the content, null if the file doesn't exist
|
| void |
retrieve(String fileName, OutputStream out, long restartAt)
Read a file ([REST] RETR).
|
| void |
retrieve(String fileName, OutputStream out, long restartAt) throws IOException
Read a file ([REST] RETR).
Parameters:
fileName - the file name
out - the output stream
restartAt - restart at the given position (0 if no restart is
required).
|
| long |
size(String fileName)
Get the size of a file (SIZE).
|
| long |
size(String fileName) throws IOException
Get the size of a file (SIZE).
Parameters:
fileName - the file name
Returns:
the size
|
| void |
store(String fileName, InputStream in)
Store a file (STOR).
|
| void |
store(String fileName, InputStream in) throws IOException
Store a file (STOR).
Parameters:
fileName - the file name
in - the input stream
|
| void |
storeRecursive(File file)
Copy a local file or directory to the FTP server, recursively.
|
| void |
storeRecursive(File file) throws IOException
Copy a local file or directory to the FTP server, recursively.
Parameters:
file - the file to copy
|