Class NFTPClient

java.lang.Object
com.netlang.ftp.NFTPClient
All Implemented Interfaces:
IFTPClient, com.netlang.io.filesystem.FileSystem

public class NFTPClient extends Object implements IFTPClient
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 Details

    • ASCII

      public static int ASCII
    • BINARY

      public static int BINARY
    • DETECT

      public static int DETECT
    • asciiExt

      public static Map<String,String> asciiExt
  • Constructor Details

    • NFTPClient

      public NFTPClient(String server, String user, String pwd) throws Exception
      Create a connection to a FTP server with the default ftp port 21.
      Parameters:
      server -
      user -
      pwd -
      Throws:
      Exception
    • NFTPClient

      public NFTPClient(String server, int port, String user, String pwd) 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) 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 milliseconds
      dataTimeout - read timeout in milliseconds
      Throws:
      Exception
  • Method Details

    • getFileNames

      public List<String> getFileNames(String pattern) throws Exception
      List files
      Parameters:
      pattern -
      Returns:
      Throws:
      Exception
    • getFiles

      public List<org.apache.commons.net.ftp.FTPFile> getFiles(String pattern) throws Exception
      List files
      Parameters:
      pattern -
      Returns:
      Throws:
      Exception
    • createFolder

      public void createFolder(String dir) throws Exception
      Create a new directory
      Specified by:
      createFolder in interface IFTPClient
      Parameters:
      dir - the directory to create
      Throws:
      Exception
    • createDir

      public int createDir(String path, boolean keepCurrentDir) throws Exception
      Create directories at remote server
      Parameters:
      path - create all directories for this path
      keepCurrentDir - true to not change the current folder
      Throws:
      Exception
    • createDir

      public int createDir(String basepath, String path, boolean keepCurrentDir) throws Exception
      Create directories at remote server
      Parameters:
      basepath - to remove from the path
      path - create all directories for this path
      keepCurrentDir - true to not change the current folder
      Throws:
      Exception
    • changeDir

      public boolean changeDir(String dir) throws Exception
      Change dir
      Specified by:
      changeDir in interface IFTPClient
      Parameters:
      dir - the directory to change to
      Returns:
      Throws:
      Exception
    • existsDir

      public boolean existsDir(String dir) throws Exception
      Check if directory exists at the server
      Parameters:
      dir - the directory to check for
      Returns:
      true if the directory exists
      Throws:
      Exception
    • existsFile

      public boolean existsFile(String file) throws Exception
      Check if a file exists at the server
      Parameters:
      file - the file to check for
      Returns:
      true if the file exists
      Throws:
      Exception
    • listDirs

      public List<String> listDirs(String pattern) throws Exception
      Get directories
      Parameters:
      pattern -
      Returns:
      Throws:
      Exception
    • listDirs

      public List<String> listDirs(String path, String pattern) throws Exception
      Get directories
      Parameters:
      pattern -
      Returns:
      Throws:
      Exception
    • listFiles

      public List<NLFile> listFiles(String path, String pattern) throws Exception
      Get files using pattern
      Parameters:
      pattern -
      Returns:
      Throws:
      Exception
    • setFileType

      public void setFileType(int fileType) throws Exception
      Set the file type.
      Parameters:
      fileType -
      Throws:
      Exception
    • getReplyCode

      public int getReplyCode()
    • getReplyString

      public String getReplyString()
    • isConnected

      public boolean isConnected()
      Return true if there is a connection to the server
      Returns:
    • changeWorkingDirectory

      public boolean changeWorkingDirectory(String pathname) throws IOException
      Throws:
      IOException
    • removeFile

      public void removeFile(String pathname) throws IOException
      Description copied from interface: IFTPClient
      Delete the specified file on the remote server.
      Specified by:
      removeFile in interface IFTPClient
      Throws:
      IOException
    • deleteFiles

      public void deleteFiles(String pattern) throws Exception
      Delete file(s) from the server
      Parameters:
      pattern - a file name where wildcard * can be used
      Throws:
      Exception
    • deleteDir

      public void deleteDir(String dir) throws Exception
      Delete directory at the server
      Parameters:
      dir - the directory to remove
      Throws:
      Exception
    • deleteDirs

      public void deleteDirs(String pattern) throws Exception
      Delete directory(s) at the server
      Parameters:
      dirs - a directory name where wildcard * can be used
      Throws:
      Exception
    • listFiles

      public org.apache.commons.net.ftp.FTPFile[] listFiles() throws IOException
      Throws:
      IOException
    • listFiles

      public List<String> listFiles(String path) throws IOException
      List files matching the pattern
      Parameters:
      pattern -
      Returns:
      Throws:
      IOException
    • makeDirectory

      public boolean makeDirectory(String pathname) throws IOException
      Throws:
      IOException
    • getFile

      public InputStream getFile(String file) throws IOException
      Description copied from interface: IFTPClient
      Returns a InputStream for the specified file.
      Specified by:
      getFile in interface IFTPClient
      Parameters:
      file - the file at the FTP server
      Returns:
      the content as an inputStream
      Throws:
      IOException
    • storeFile

      public boolean storeFile(String remote, InputStream local) throws IOException
      Throws:
      IOException
    • close

      public void close()
      Close the connection.
      Specified by:
      close in interface IFTPClient
      Throws:
      Exception
    • get

      public void get(String from, String to, boolean subdirs, int mode) throws Exception
      Get file(s) from server
      Parameters:
      from -
      to -
      subdirs -
      Throws:
      Exception
    • putSilent

      public boolean putSilent(String from, String to, boolean subdirs, int mode)
      Send file(s) to the server
      Parameters:
      from -
      to -
      subdirs -
      Throws:
      Exception
    • put

      public void put(String from, String to, boolean subdirs, int mode) throws Exception
      Send file(s) to the server
      Parameters:
      from -
      to -
      subdirs -
      Throws:
      Exception
    • moveUp

      public void moveUp(int levels) throws Exception
      Move up in directory tree
      Parameters:
      levels -
      Throws:
      Exception
    • put

      public void put(InputStream input, String tofile) throws Exception
      Send file to server
      Parameters:
      input - the stream to store
      tofile - the remote file name
      Throws:
      Exception
    • putFile

      public void putFile(String fromfile, String tofile) throws Exception
      Send a file to the server
      Specified by:
      putFile in interface IFTPClient
      Parameters:
      fromfile -
      tofile -
      Throws:
      Exception
    • changeMode

      public void changeMode(String filepath) throws IOException
      Change transfer mode based on file extension
      Parameters:
      filepath -
      Throws:
      IOException
    • ascii

      public void ascii() throws IOException
      Change to ascii mode
      Throws:
      IOException
    • binary

      public void binary() throws IOException
      Change to binary mode
      Throws:
      IOException
    • renameFile

      public void renameFile(String originalFileName, String newFileName) throws Exception
      Rename a file
      Parameters:
      originalFileName - the file to rename
      newFileName - the new name of the file
      Throws:
      Exception
    • getFileSize

      public long getFileSize(String filename) throws Exception
      Get size of a file
      Specified by:
      getFileSize in interface IFTPClient
      Parameters:
      filename - the name of the file
      Returns:
      the size of the file or -1
      Throws:
      Exception
    • sendCommand

      public String sendCommand(String command, String args) throws Exception
      Send a FTP command to the server
      Specified by:
      sendCommand in interface IFTPClient
      Parameters:
      command - the command to send
      args - parameters to the command
      Returns:
      response code from the command
      Throws:
      Exception
    • get

      public void get(String remotefile, String toLocalFolder) throws com.net4z.APIException
      Get file from server
      Specified by:
      get in interface IFTPClient
      Parameters:
      remotefile - the remote file name
      toLocalFolder - 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:
      get in interface IFTPClient
      Parameters:
      remotefile - the remote file name
      toLocalFolder - the folder where to store the transfered file
      toLocalFile - the name of the transfered file
      Throws:
      com.net4z.APIException
    • transferFile

      public void transferFile(String remotefile, String toLocalFolder) throws com.net4z.APIException
      Description copied from interface: IFTPClient
      Download a file from the FTP server to a local folder.
      Specified by:
      transferFile in interface IFTPClient
      Parameters:
      remotefile - the remote file
      toLocalFolder - the local folder
      Throws:
      com.net4z.APIException
    • transferFile

      public void transferFile(String remotefile, String toLocalFolder, String toLocalFile) throws com.net4z.APIException
      Specified by:
      transferFile in interface IFTPClient
      Throws:
      com.net4z.APIException
    • list

      public List<NLFile> list(String path, String pattern, int type) throws Exception
      Description copied from interface: IFTPClient
      List all directories that matches the specified pattern.
      Specified by:
      list in interface IFTPClient
      Parameters:
      path - the path
      pattern - the pattern
      Returns:
      Throws:
      Exception
    • listFiles

      public List<NLFile> listFiles(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      listFiles in interface com.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:
      listFolders in interface com.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:
      listTree in interface com.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:
      extract in interface com.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:
      write in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • existFile

      public boolean existFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      existFile in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • getFilePath

      public FileReference getFilePath(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      getFilePath in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • mkdir

      public void mkdir(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      mkdir in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • remove

      public void remove(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      remove in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • rename

      public void rename(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      rename in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • lastModifiedFile

      public long lastModifiedFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      lastModifiedFile in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • sizeFile

      public long sizeFile(com.netlang.io.filesystem.FileSystemParm parm) throws com.net4z.APIException
      Specified by:
      sizeFile in interface com.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:
      moveOrCopySameSubtype in interface com.netlang.io.filesystem.FileSystem
      Throws:
      com.net4z.APIException
    • put

      public void put(NetlangFile from, String path, FileOptions options) throws com.net4z.APIException
      Specified by:
      put in interface IFTPClient
      Throws:
      com.net4z.APIException
    • put

      public void put(File from, String path, FileOptions options) throws com.net4z.APIException
      Specified by:
      put in interface IFTPClient
      Throws:
      com.net4z.APIException
    • put

      public void put(String from, String path, FileOptions options) throws com.net4z.APIException
      Specified by:
      put in interface IFTPClient
      Throws:
      com.net4z.APIException
    • put

      public void put(String fromResourceId, String frompath, String remotePath, FileOptions options) throws com.net4z.APIException
      Specified by:
      put in interface IFTPClient
      Throws:
      com.net4z.APIException
    • get

      public void get(String path, NetlangFile to) throws com.net4z.APIException
      Specified by:
      get in interface IFTPClient
      Throws:
      com.net4z.APIException
    • get

      public void get(String path, File to) throws com.net4z.APIException
      Specified by:
      get in interface IFTPClient
      Throws:
      com.net4z.APIException