Package org.h2.dev.ftp
Class FtpClient
- java.lang.Object
-
- org.h2.dev.ftp.FtpClient
-
public class FtpClient extends java.lang.ObjectA simple standalone FTP client.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeDirectoryUp()Change to the parent directory (CDUP).voidchangeWorkingDirectory(java.lang.String dir)Change the working directory (CWD).voidclose()Close the connection (QUIT).booleanexists(java.lang.String dir, java.lang.String name)Check if a file exists on the FTP server.java.lang.Stringlist(java.lang.String dir)Get the directory listing (LIST).java.io.File[]listFiles(java.lang.String dir)List the files on the FTP server.voidlogin(java.lang.String userName, java.lang.String password)Login to this FTP server (USER, PASS, SYST, SITE, STRU F, TYPE I).voidmakeDirectory(java.lang.String dir)Create a directory (MKD).java.lang.StringnameList(java.lang.String dir)Get the directory listing (NLST).static FtpClientopen(java.lang.String url)Open an FTP connection.voidremoveDirectory(java.lang.String dir)Remove a directory (RMD).voidremoveDirectoryRecursive(java.lang.String dir)Remove all files and directory in a directory, and then delete the directory itself.byte[]retrieve(java.lang.String fileName)Read a file.voidstore(java.lang.String fileName, java.io.InputStream in)Store a file (STOR).voidstoreRecursive(java.io.File file)Copy a local file or directory to the FTP server, recursively.
-
-
-
Method Detail
-
open
public static FtpClient open(java.lang.String url) throws java.io.IOException
Open an FTP connection.- Parameters:
url- the FTP URL- Returns:
- the ftp client object
- Throws:
java.io.IOException
-
login
public void login(java.lang.String userName, java.lang.String password) throws java.io.IOExceptionLogin to this FTP server (USER, PASS, SYST, SITE, STRU F, TYPE I).- Parameters:
userName- the user namepassword- the password- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionClose the connection (QUIT).- Throws:
java.io.IOException
-
changeWorkingDirectory
public void changeWorkingDirectory(java.lang.String dir) throws java.io.IOExceptionChange the working directory (CWD).- Parameters:
dir- the new directory- Throws:
java.io.IOException
-
changeDirectoryUp
public void changeDirectoryUp() throws java.io.IOExceptionChange to the parent directory (CDUP).- Throws:
java.io.IOException
-
makeDirectory
public void makeDirectory(java.lang.String dir) throws java.io.IOExceptionCreate a directory (MKD).- Parameters:
dir- the directory to create- Throws:
java.io.IOException
-
retrieve
public byte[] retrieve(java.lang.String fileName) throws java.io.IOExceptionRead a file.- Parameters:
fileName- the file name- Returns:
- the content, null if the file doesn't exist
- Throws:
java.io.IOException
-
removeDirectory
public void removeDirectory(java.lang.String dir) throws java.io.IOExceptionRemove a directory (RMD).- Parameters:
dir- the directory to remove- Throws:
java.io.IOException
-
removeDirectoryRecursive
public void removeDirectoryRecursive(java.lang.String dir) throws java.io.IOExceptionRemove all files and directory in a directory, and then delete the directory itself.- Parameters:
dir- the directory to remove- Throws:
java.io.IOException
-
store
public void store(java.lang.String fileName, java.io.InputStream in) throws java.io.IOExceptionStore a file (STOR).- Parameters:
fileName- the file namein- the input stream- Throws:
java.io.IOException
-
storeRecursive
public void storeRecursive(java.io.File file) throws java.io.IOExceptionCopy a local file or directory to the FTP server, recursively.- Parameters:
file- the file to copy- Throws:
java.io.IOException
-
nameList
public java.lang.String nameList(java.lang.String dir) throws java.io.IOExceptionGet the directory listing (NLST).- Parameters:
dir- the directory- Returns:
- the listing
- Throws:
java.io.IOException
-
list
public java.lang.String list(java.lang.String dir) throws java.io.IOExceptionGet the directory listing (LIST).- Parameters:
dir- the directory- Returns:
- the listing
- Throws:
java.io.IOException
-
exists
public boolean exists(java.lang.String dir, java.lang.String name) throws java.io.IOExceptionCheck if a file exists on the FTP server.- Parameters:
dir- the directoryname- the directory or file name- Returns:
- true if it exists
- Throws:
java.io.IOException
-
listFiles
public java.io.File[] listFiles(java.lang.String dir) throws java.io.IOExceptionList the files on the FTP server.- Parameters:
dir- the directory- Returns:
- the list of files
- Throws:
java.io.IOException
-
-