Package com.netlang.ftp
Class NFTPClient
java.lang.Object
com.netlang.ftp.NFTPClient
- All Implemented Interfaces:
IFTPClient,com.netlang.io.filesystem.FileSystem
This class communicates with standard FTP servers
IFTPClient sftpClient1 = new NFTPClient("myftpserver.com",22,"username","password");
sftpClient1.get("/TEST/list.txt",new File("C:\\Netlang"));
sftpClient1.close();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intstatic intstatic intFields inherited from interface com.netlang.ftp.IFTPClient
TYPE_BOTH, TYPE_DIR, TYPE_FILE -
Constructor Summary
ConstructorsConstructorDescriptionNFTPClient(String server, int port, String user, String pwd) Create a connection to the specified hostNFTPClient(String server, int port, String user, String pwd, boolean ssl, boolean implicit, boolean encryptData, boolean passive) Create a connection to the specified hostNFTPClient(String server, int port, String user, String pwd, boolean ssl, boolean implicit, boolean encryptData, boolean passive, int connectTimeout, int dataTimeout) Create a connection to the specified hostNFTPClient(String server, String user, String pwd) Create a connection to a FTP server with the default ftp port 21. -
Method Summary
Modifier and TypeMethodDescriptionvoidascii()Change to ascii modevoidbinary()Change to binary modebooleanChange dirvoidchangeMode(String filepath) Change transfer mode based on file extensionbooleanchangeWorkingDirectory(String pathname) voidclose()Close the connection.intCreate directories at remote serverintCreate directories at remote servervoidcreateFolder(String dir) Create a new directoryvoidDelete directory at the servervoiddeleteDirs(String pattern) Delete directory(s) at the servervoiddeleteFiles(String pattern) Delete file(s) from the serverbooleanexistFile(com.netlang.io.filesystem.FileSystemParm parm) booleanCheck if directory exists at the serverbooleanexistsFile(String file) Check if a file exists at the servercom.netlang.io.filesystem.FileSystemContentextract(com.netlang.io.filesystem.FileSystemParm parm) voidget(String path, NetlangFile to) voidvoidGet file from servervoidGet file(s) from servervoidGet file from serverReturns a InputStream for the specified file.getFileNames(String pattern) List filesgetFilePath(com.netlang.io.filesystem.FileSystemParm parm) List<org.apache.commons.net.ftp.FTPFile>List fileslonggetFileSize(String filename) Get size of a fileorg.apache.commons.net.ftp.FTPClientReturns the internal FTP clientintbooleanReturn true if there is a connection to the serverlonglastModifiedFile(com.netlang.io.filesystem.FileSystemParm parm) List all directories that matches the specified pattern.Get directoriesGet directoriesorg.apache.commons.net.ftp.FTPFile[]listFiles(com.netlang.io.filesystem.FileSystemParm parm) List files matching the patternGet files using patternlistFolders(com.netlang.io.filesystem.FileSystemParm parm) listTree(com.netlang.io.filesystem.FileSystemParm parm) booleanmakeDirectory(String pathname) voidmkdir(com.netlang.io.filesystem.FileSystemParm parm) voidmoveOrCopySameSubtype(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystem fromFs) voidmoveUp(int levels) Move up in directory treevoidput(NetlangFile from, String path, FileOptions options) voidput(File from, String path, FileOptions options) voidput(InputStream input, String tofile) Send file to servervoidSend file(s) to the servervoidput(String from, String path, FileOptions options) voidput(String fromResourceId, String frompath, String remotePath, FileOptions options) voidSend a file to the serverbooleanSend file(s) to the servervoidremove(com.netlang.io.filesystem.FileSystemParm parm) voidremoveFile(String pathname) Delete the specified file on the remote server.voidrename(com.netlang.io.filesystem.FileSystemParm parm) voidrenameFile(String originalFileName, String newFileName) Rename a filesendCommand(String command, String args) Send a FTP command to the servervoidsetFileType(int fileType) Set the file type.longsizeFile(com.netlang.io.filesystem.FileSystemParm parm) booleanstoreFile(String remote, InputStream local) voidtransferFile(String remotefile, String toLocalFolder) Download a file from the FTP server to a local folder.voidtransferFile(String remotefile, String toLocalFolder, String toLocalFile) voidwrite(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystemContent content)
-
Field Details
-
ASCII
public static int ASCII -
BINARY
public static int BINARY -
DETECT
public static int DETECT -
asciiExt
-
-
Constructor Details
-
NFTPClient
Create a connection to a FTP server with the default ftp port 21.- Parameters:
server-user-pwd-- Throws:
Exception
-
NFTPClient
Create a connection to the specified host- Parameters:
server-port-user-pwd-- Throws:
Exception
-
NFTPClient
public NFTPClient(String server, int port, String user, String pwd, boolean ssl, boolean implicit, boolean encryptData, boolean passive) throws Exception Create a connection to the specified host- Parameters:
server-port-user-pwd-- Throws:
Exception
-
NFTPClient
public NFTPClient(String server, int port, String user, String pwd, boolean ssl, boolean implicit, boolean encryptData, boolean passive, int connectTimeout, int dataTimeout) throws Exception Create a connection to the specified host- Parameters:
server-port-user-pwd-connectTimeout- connection timeout in millisecondsdataTimeout- read timeout in milliseconds- Throws:
Exception
-
-
Method Details
-
getFileNames
List files- Parameters:
pattern-- Returns:
- Throws:
Exception
-
getFiles
List files- Parameters:
pattern-- Returns:
- Throws:
Exception
-
createFolder
Create a new directory- Specified by:
createFolderin interfaceIFTPClient- Parameters:
dir- the directory to create- Throws:
Exception
-
createDir
Create directories at remote server- Parameters:
path- create all directories for this pathkeepCurrentDir- true to not change the current folder- Throws:
Exception
-
createDir
Create directories at remote server- Parameters:
basepath- to remove from the pathpath- create all directories for this pathkeepCurrentDir- true to not change the current folder- Throws:
Exception
-
changeDir
Change dir- Specified by:
changeDirin interfaceIFTPClient- Parameters:
dir- the directory to change to- Returns:
- Throws:
Exception
-
existsDir
Check if directory exists at the server- Parameters:
dir- the directory to check for- Returns:
- true if the directory exists
- Throws:
Exception
-
existsFile
Check if a file exists at the server- Parameters:
file- the file to check for- Returns:
- true if the file exists
- Throws:
Exception
-
listDirs
Get directories- Parameters:
pattern-- Returns:
- Throws:
Exception
-
listDirs
Get directories- Parameters:
pattern-- Returns:
- Throws:
Exception
-
listFiles
Get files using pattern- Parameters:
pattern-- Returns:
- Throws:
Exception
-
setFileType
Set the file type.- Parameters:
fileType-- Throws:
Exception
-
getReplyCode
public int getReplyCode() -
getReplyString
-
isConnected
public boolean isConnected()Return true if there is a connection to the server- Returns:
-
changeWorkingDirectory
- Throws:
IOException
-
removeFile
Description copied from interface:IFTPClientDelete the specified file on the remote server.- Specified by:
removeFilein interfaceIFTPClient- Throws:
IOException
-
deleteFiles
Delete file(s) from the server- Parameters:
pattern- a file name where wildcard * can be used- Throws:
Exception
-
deleteDir
Delete directory at the server- Parameters:
dir- the directory to remove- Throws:
Exception
-
deleteDirs
Delete directory(s) at the server- Parameters:
dirs- a directory name where wildcard * can be used- Throws:
Exception
-
listFiles
- Throws:
IOException
-
listFiles
List files matching the pattern- Parameters:
pattern-- Returns:
- Throws:
IOException
-
makeDirectory
- Throws:
IOException
-
getFile
Description copied from interface:IFTPClientReturns a InputStream for the specified file.- Specified by:
getFilein interfaceIFTPClient- Parameters:
file- the file at the FTP server- Returns:
- the content as an inputStream
- Throws:
IOException
-
storeFile
- Throws:
IOException
-
close
public void close()Close the connection.- Specified by:
closein interfaceIFTPClient- Throws:
Exception
-
get
Get file(s) from server- Parameters:
from-to-subdirs-- Throws:
Exception
-
putSilent
Send file(s) to the server- Parameters:
from-to-subdirs-- Throws:
Exception
-
put
Send file(s) to the server- Parameters:
from-to-subdirs-- Throws:
Exception
-
moveUp
Move up in directory tree- Parameters:
levels-- Throws:
Exception
-
put
Send file to server- Parameters:
input- the stream to storetofile- the remote file name- Throws:
Exception
-
putFile
Send a file to the server- Specified by:
putFilein interfaceIFTPClient- Parameters:
fromfile-tofile-- Throws:
Exception
-
changeMode
Change transfer mode based on file extension- Parameters:
filepath-- Throws:
IOException
-
ascii
Change to ascii mode- Throws:
IOException
-
binary
Change to binary mode- Throws:
IOException
-
renameFile
Rename a file- Parameters:
originalFileName- the file to renamenewFileName- the new name of the file- Throws:
Exception
-
getFileSize
Get size of a file- Specified by:
getFileSizein interfaceIFTPClient- Parameters:
filename- the name of the file- Returns:
- the size of the file or -1
- Throws:
Exception
-
sendCommand
Send a FTP command to the server- Specified by:
sendCommandin interfaceIFTPClient- Parameters:
command- the command to sendargs- parameters to the command- Returns:
- response code from the command
- Throws:
Exception
-
get
Get file from server- Specified by:
getin interfaceIFTPClient- Parameters:
remotefile- the remote file nametoLocalFolder- the folder where to store the transfered file- Throws:
com.net4z.APIException
-
getInternalClient
public org.apache.commons.net.ftp.FTPClient getInternalClient()Returns the internal FTP client- Returns:
-
get
public void get(String remotefile, String toLocalFolder, String toLocalFile) throws com.net4z.APIException Get file from server- Specified by:
getin interfaceIFTPClient- Parameters:
remotefile- the remote file nametoLocalFolder- the folder where to store the transfered filetoLocalFile- the name of the transfered file- Throws:
com.net4z.APIException
-
transferFile
Description copied from interface:IFTPClientDownload a file from the FTP server to a local folder.- Specified by:
transferFilein interfaceIFTPClient- Parameters:
remotefile- the remote filetoLocalFolder- the local folder- Throws:
com.net4z.APIException
-
transferFile
public void transferFile(String remotefile, String toLocalFolder, String toLocalFile) throws com.net4z.APIException - Specified by:
transferFilein interfaceIFTPClient- Throws:
com.net4z.APIException
-
list
Description copied from interface:IFTPClientList all directories that matches the specified pattern.- Specified by:
listin interfaceIFTPClient- Parameters:
path- the pathpattern- the pattern- Returns:
- Throws:
Exception
-
listFiles
public List<NLFile> listFiles(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
listFilesin interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
listFolders
public List<String> listFolders(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
listFoldersin interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
listTree
public List<NLFile> listTree(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
listTreein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
extract
public com.netlang.io.filesystem.FileSystemContent extract(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
extractin interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
write
public void write(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystemContent content) throws com.net4z.APIException - Specified by:
writein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
existFile
public boolean existFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
existFilein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
getFilePath
public FileReference getFilePath(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
getFilePathin interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
mkdir
public void mkdir(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
mkdirin interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
remove
public void remove(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
removein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
rename
public void rename(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
renamein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
lastModifiedFile
public long lastModifiedFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
lastModifiedFilein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
sizeFile
public long sizeFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException - Specified by:
sizeFilein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
moveOrCopySameSubtype
public void moveOrCopySameSubtype(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystem fromFs) throws com.net4z.APIException - Specified by:
moveOrCopySameSubtypein interfacecom.netlang.io.filesystem.FileSystem- Throws:
com.net4z.APIException
-
put
- Specified by:
putin interfaceIFTPClient- Throws:
com.net4z.APIException
-
put
- Specified by:
putin interfaceIFTPClient- Throws:
com.net4z.APIException
-
put
- Specified by:
putin interfaceIFTPClient- Throws:
com.net4z.APIException
-
put
public void put(String fromResourceId, String frompath, String remotePath, FileOptions options) throws com.net4z.APIException - Specified by:
putin interfaceIFTPClient- Throws:
com.net4z.APIException
-
get
- Specified by:
getin interfaceIFTPClient- Throws:
com.net4z.APIException
-
get
- Specified by:
getin interfaceIFTPClient- Throws:
com.net4z.APIException
-