Package com.netlang.ftp
Class NSFTPClient
java.lang.Object
com.netlang.ftp.NSFTPClient
- All Implemented Interfaces:
IFTPClient,com.netlang.io.filesystem.FileSystem
This class communicates with FTP servers with the SSH File Transfer protocol.
The class provides file access, file transfer, and file management functionalities over any reliable data stream.
The class provides file access, file transfer, and file management functionalities over any reliable data stream.
IFTPClient sftpClient1 = new NSFTPClient("myftpserver.com",22,"username","password",null);
sftpClient1.get("/TEST/list.txt",new File("C:\\Netlang"));
sftpClient1.close();
-
Field Summary
Fields inherited from interface com.netlang.ftp.IFTPClient
TYPE_BOTH, TYPE_DIR, TYPE_FILE -
Constructor Summary
ConstructorsConstructorDescriptionNSFTPClient(com.netlang.session.NetlangSession session, com.netlang.resourceconfig.ResourceConfig config) NSFTPClient(com.netlang.session.NetlangSession session, String resourceid) NSFTPClient(String resourceid) NSFTPClient(String host, int port, String userid, File privateKey) NSFTPClient(String host, int port, String userid, String password) Connects to an SSH FTP serverNSFTPClient(String host, int port, String userid, String password, String knownhosts) Connects to an SSH FTP server, validating the public key against a list of known hosts.NSFTPClient(String host, int port, String userid, String password, String knownhosts, com.netlang.session.NetlangSession nSession, com.netlang.resourceconfig.ResourceConfig config) NSFTPClient(String host, int port, String userid, String keyfile, String passphrase, String knownhosts) Creates a connection with public key authentication.NSFTPClient(String host, String userid, String password) Connects to an SSH FTP server with the default port 22. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChange the current working directory.voidchangePermission(int permissions, String path) voidclose()Close this connection.voidcreateFolder(String path) Make remote directorybooleanexistFile(com.netlang.io.filesystem.FileSystemParm parm) com.netlang.io.filesystem.FileSystemContentextract(com.netlang.io.filesystem.FileSystemParm parm) booleanCheck if any files matches the specified pattern.voidget(String path, NetlangFile to) voidvoidvoidCopy an entire folder and optional its subfolders to the local disc.voidReturns a InputStream for the specified file.getFilePath(com.netlang.io.filesystem.FileSystemParm parm) longgetFileSize(String filename) Returns the size on disc of the specified filebooleanCheck if the connection is active.booleanisDirectory(String dir) Check whether the specified string is a directory.longlastModifiedFile(com.netlang.io.filesystem.FileSystemParm parm) List all directories that matches the specified pattern.List all directories in the current directory.listFiles(com.netlang.io.filesystem.FileSystemParm parm) List all files according to the specified pattern in the current directorylistFolders(com.netlang.io.filesystem.FileSystemParm parm) listTree(com.netlang.io.filesystem.FileSystemParm parm) static voidvoidmakeRemotedir(String basepath, String path) Create a directory on the FTPvoidmkdir(com.netlang.io.filesystem.FileSystemParm parm) voidmoveOrCopySameSubtype(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystem fromFs) voidput(NetlangFile from, String path, FileOptions options) voidput(File from, String path, FileOptions options) voidput(String from, String path, FileOptions options) voidput(String resourceid, String frompath, String remotePath, FileOptions options) voidUpload a file to the ftpvoidCopy all files in the specified folder to the FTP servervoidremove(com.netlang.io.filesystem.FileSystemParm parm) voidremoveFile(String file) delete remote filevoidremoveFolder(String path) delete remote filevoidrename(com.netlang.io.filesystem.FileSystemParm parm) voidrenameFile(String origFile, String newFileName) Rename a file on the FTPvoidrevertChangeFolder(int levels) Traverse back in the folder structure.sendCommand(String command, String parameter) Send a (raw) command to the FTP server.longsizeFile(com.netlang.io.filesystem.FileSystemParm parm) voidtransferFile(String remotefile, String localfile) Copy the remote file to the local pathvoidtransferFile(String remotefile, String toLocalFolder, String toLocalFile) voidwrite(com.netlang.io.filesystem.FileSystemParm parm, com.netlang.io.filesystem.FileSystemContent content)
-
Constructor Details
-
NSFTPClient
public NSFTPClient(com.netlang.session.NetlangSession session, com.netlang.resourceconfig.ResourceConfig config) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
NSFTPClient
- Throws:
com.net4z.APIException
-
NSFTPClient
public NSFTPClient(com.netlang.session.NetlangSession session, String resourceid) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
NSFTPClient
Connects to an SSH FTP server with the default port 22.- Parameters:
host- the dns name or ipuserid- the usernamepassword- the password- Throws:
Exception
-
NSFTPClient
public NSFTPClient(String host, int port, String userid, String password, String knownhosts) throws com.net4z.APIException Connects to an SSH FTP server, validating the public key against a list of known hosts. The known host file could be generated with third part programs or manually created using the following format.[, ...] ssh-rsa|ssh-dsa - Parameters:
host- the dns name or ipuserid- the usernamepassword- the passwordport- the port, default 22.knownhosts- the path to the knownhosts file.- Throws:
Exceptioncom.net4z.APIException
-
NSFTPClient
public NSFTPClient(String host, int port, String userid, String password, String knownhosts, com.netlang.session.NetlangSession nSession, com.netlang.resourceconfig.ResourceConfig config) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
NSFTPClient
- Throws:
Exception
-
NSFTPClient
public NSFTPClient(String host, int port, String userid, String keyfile, String passphrase, String knownhosts) throws Exception Creates a connection with public key authentication. Initializes a newly createdSFTPConnection- Parameters:
host- the dns name or ipuserid- the usernameport- the port, default 22.keyfile- the file to the private and public key in OpenSSH formatpassphrase- the password for the given keyknownhosts- a list with known hosts or null if no verification should be made.- Throws:
Exception
-
NSFTPClient
Connects to an SSH FTP server- Parameters:
host- the dns name or ipuserid- the usernamepassword- the passwordport- the port, default 22.- Throws:
Exception
-
-
Method Details
-
main
- Throws:
Exception
-
putFolder
Copy all files in the specified folder to the FTP server- Parameters:
from- the folder to copyto- the folder where to place the files.- Throws:
Exception
-
putFile
Upload a file to the ftp- Specified by:
putFilein interfaceIFTPClient- Throws:
Exception
-
get
Copy an entire folder and optional its subfolders to the local disc.- Parameters:
from- the path to copy fromto- the new path on the local diskcopySubdirs- if true all subfolders and its content will be copied.- Throws:
Exception
-
transferFile
Copy the remote file to the local path- Specified by:
transferFilein interfaceIFTPClient- Parameters:
remotefile- the file to copylocalfile- the local file- Throws:
Exception
-
listDirs
List all directories in the current directory.- Parameters:
pattern- the pattern- Returns:
- Throws:
Exception
-
listFiles
List all files according to the specified pattern in the current directory- Parameters:
pattern- the pattern- Returns:
- a list with file names
- Throws:
Exception
-
listFiles
- Throws:
Exception
-
changePermission
- Parameters:
path-- Throws:
Exception
-
changeDir
Description copied from interface:IFTPClientChange the current working directory.- Specified by:
changeDirin interfaceIFTPClient- Parameters:
path-- Returns:
- true always otherwise an exception will be thrown.
- Throws:
Exception
-
revertChangeFolder
Traverse back in the folder structure.- Parameters:
levels-- Throws:
Exception
-
createFolder
Make remote directory- Specified by:
createFolderin interfaceIFTPClient- Parameters:
path-- Throws:
Exception
-
removeFolder
delete remote file- Parameters:
path-- Throws:
Exception
-
removeFile
delete remote file- Specified by:
removeFilein interfaceIFTPClient- Parameters:
path-- Throws:
Exception
-
close
public void close()Close this connection.- Specified by:
closein interfaceIFTPClient
-
findFile
Check if any files matches the specified pattern.- Parameters:
pattern-- Returns:
- Throws:
Exception
-
renameFile
Rename a file on the FTP- Parameters:
origFile-newFileName-- Throws:
Exception
-
getFileSize
Returns the size on disc of the specified file- Specified by:
getFileSizein interfaceIFTPClient- Parameters:
filename-- Returns:
- Throws:
Exception
-
isConnected
public boolean isConnected()Check if the connection is active.- Returns:
-
isDirectory
Check whether the specified string is a directory.- Parameters:
dir-- Returns:
-
makeRemotedir
Create a directory on the FTP- Parameters:
basepath-path-- Throws:
Exception
-
sendCommand
Send a (raw) command to the FTP server.- Specified by:
sendCommandin interfaceIFTPClient- Parameters:
command- the commandparameter- the parameters- Returns:
- the result from the ftp server
- Throws:
Exception
-
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:
Exception
-
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
-
transferFile
public void transferFile(String remotefile, String toLocalFolder, String toLocalFile) throws Exception - Specified by:
transferFilein interfaceIFTPClient- 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 resourceid, 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
-
get
- Specified by:
getin interfaceIFTPClient- Throws:
com.net4z.APIException
-
get
public void get(String remotePath, String toResourceId, String toFile) throws com.net4z.APIException - Specified by:
getin interfaceIFTPClient- Throws:
com.net4z.APIException
-