com.ibm.as400.access

Class AS400FTP

  • All Implemented Interfaces:
    java.io.Serializable


    public class AS400FTP
    extends FTP
    implements java.io.Serializable
    Represents a client for the IBM i FTP server. It is written to take advantage of IBM i features. Use the parent class, FTP, if you need a generic client.

    AS400FTP does the following extra processing:

    1. Using the AS400 object to determine system name, userid and password so these properties can be shared with other Toolbox classes. If you use the FTP class, your application must set the system name, userid, and password in both the FTP class and other Toolbox classes.

      One restriction when the client is an IBM i system -- the userid and password must be set on the AS400 object in this environment. That is, *CURRENT will not work when connecting from one IBM i system to another IBM i system.

    2. Automatically setting the current directory to the root directory on the system when a connection is made. If the FTP class is used, the root may be QSYS.LIB when a connection is made. The integrated file system name of objects in libraries must be used to access them. For example, /QSYS.LIB/MYLIB.LIB/MYFILE.FILE. See QSYSObjectPathName documentation for more information.
    3. Handling extra work necessary to put a save file to the system. If you use the FTP class, you have to do the extra steps. The extra processing is done only if the extension of the file is .savf and the file will be put into an IBM i library.

      The extra processing includes internally using Toolbox CommandCall to create the save file on the system. The default *Public authority is *EXCLUDE. Use the setSaveFilePublicAuthority() method to change the *Public authority value specified on the create save file command.

    No encryption is provided by this class. The userid and password flow un-encrypted to the system. This class is not SSL enabled.

    The forward slash is the separator character for paths sent to the FTP server.

    The following example puts a save file to the system. Note the application does not set data transfer type to binary or use Toolbox CommandCall to create the save file. Since the extension is .savf, AS400FTP class detects the file to put is a save file so it does these step automatically.

     AS400 system = new AS400();
     AS400FTP   ftp    = new AS400FTP(system);
     ftp.put("myData.savf", "/QSYS.LIB/MYLIB.LIB/MYDATA.SAVF");
     
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      AS400FTP()
      Constructs an AS400FTP object.
      AS400FTP(AS400 system)
      Constructs an AS400FTP object.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean append(java.io.File sourceFileName, java.lang.String targetFileName)
      Appends to a file on the system.
      java.io.OutputStream append(java.lang.String fileName)
      Starts the process of appending to a file on the system.
      boolean append(java.lang.String sourceFileName, java.lang.String targetFileName)
      Appends to a file on the system.
      boolean cd(java.lang.String directory)
      Sets the current directory on the system to directory.
      boolean connect()
      Connects to the system.
      java.lang.String[] dir()
      Lists the contents of the current working directory.
      java.lang.String[] dir(java.lang.String criteria)
      Lists the contents of the current directory.
      java.io.InputStream get(java.lang.String fileName)
      Starts the process of getting a file from the system.
      boolean get(java.lang.String sourceFileName, java.io.File targetFile)
      Gets a file from the system.
      boolean get(java.lang.String sourceFileName, java.lang.String targetFileName)
      Gets a file from the system.
      java.lang.String getCurrentDirectory()
      Returns the current directory on the system.
      java.lang.String getSaveFilePublicAuthority()
      Returns the public authority of save files created by this object.
      AS400 getSystem()
      Returns the name of the system.
      java.lang.String issueCommand(java.lang.String cmd)
      Sends a command to the system, returning the reply from the system.
      java.lang.String[] ls()
      Lists the contents of the current working directory.
      java.lang.String[] ls(java.lang.String criteria)
      Lists the contents of the current directory.
      boolean noop()
      Sends the NOOP (no operation) command to the system.
      boolean put(java.io.File sourceFileName, java.lang.String targetFileName)
      Puts a file to the system.
      java.io.OutputStream put(java.lang.String fileName)
      Starts the process of putting a file to the system.
      boolean put(java.lang.String sourceFileName, java.lang.String targetFileName)
      Puts a file to the system.
      java.lang.String pwd()
      Returns the current directory on the system.
      boolean setCurrentDirectory(java.lang.String directory)
      Sets the current directory on the system to directory.
      void setDataTransferType(int transferType)
      Sets the data transfer type.
      void setPassword(java.lang.String password)
      Calling setPassword() is valid only for FTP objects.
      void setSaveFilePublicAuthority(java.lang.String publicAuthority)
      Sets the public authority of save files created by this object.
      void setServer(java.lang.String server)
      Calling setServer() is valid only for FTP objects.
      void setSystem(AS400 system)
      Sets the name of the system.
      void setUser(java.lang.String user)
      Calling setUser() is valid only for FTP objects.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AS400FTP

        public AS400FTP(AS400 system)
        Constructs an AS400FTP object.
        Parameters:
        system - The system to which to connect.
    >
    • Method Detail

      • append

        public java.io.OutputStream append(java.lang.String fileName)
                                    throws java.io.IOException
        Starts the process of appending to a file on the system. AS400FTP opens the data connection to the system, then opens the file on the system and returns an output stream to the caller. The caller then writes the file's data to the output stream.
        Overrides:
        append in class FTP
        Parameters:
        fileName - The file to put.
        Returns:
        An output stream to the file. The caller uses the output stream to write data to the file. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • append

        public boolean append(java.lang.String sourceFileName,
                     java.lang.String targetFileName)
                       throws java.io.IOException
        Appends to a file on the system.
        Overrides:
        append in class FTP
        Parameters:
        sourceFileName - The file to put.
        targetFileName - The file on the system.
        Returns:
        true if the append was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • append

        public boolean append(java.io.File sourceFileName,
                     java.lang.String targetFileName)
                       throws java.io.IOException
        Appends to a file on the system.
        Overrides:
        append in class FTP
        Parameters:
        sourceFileName - The file to put.
        targetFileName - The file on the system.
        Returns:
        true if the append was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • cd

        public boolean cd(java.lang.String directory)
                   throws java.io.IOException
        Sets the current directory on the system to directory. The method is the same as setCurrentDirectory(). The message returned from the system is saved. Use getLastMessage() to retrieve it.
        Overrides:
        cd in class FTP
        Parameters:
        directory - The current directory to set on the system.
        Returns:
        true if directory changed; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • connect

        public boolean connect()
                        throws java.net.UnknownHostException,
                               java.io.IOException,
                               java.lang.IllegalStateException
        Connects to the system. The AS400 object must be set before calling this method. Calling connect is optional. Methods that communicate with the system such as get, put, cd, and ls call connect() if necessary. The message returned from the system is saved. Use getLastMessage() to retrieve it.
        Overrides:
        connect in class FTP
        Returns:
        true if connection is successful; false otherwise.
        Throws:
        java.net.UnknownHostException - If a path to the system cannot be found.
        java.io.IOException - If an error occurs while connecting to the system.
        java.lang.IllegalStateException - If called before user and password are set.
        See Also:
        setSystem(com.ibm.as400.access.AS400)
      • dir

        public java.lang.String[] dir()
                               throws java.io.IOException
        Lists the contents of the current working directory. File name and attributes are returned for each entry in the directory. An array of length zero is returned if the directory is empty.
        Overrides:
        dir in class FTP
        Returns:
        The contents of the directory as an array of Strings.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • dir

        public java.lang.String[] dir(java.lang.String criteria)
                               throws java.io.IOException
        Lists the contents of the current directory. File name and attributes are returned for each entry in the directory. A zero length array is returned if the directory is empty or if no files match the search criteria.
        Overrides:
        dir in class FTP
        Parameters:
        criteria - The search criteria.
        Returns:
        The contents of the directory as an array of Strings.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • get

        public java.io.InputStream get(java.lang.String fileName)
                                throws java.io.IOException,
                                       java.io.FileNotFoundException
        Starts the process of getting a file from the system. AS400FTP opens the data connection to the system, then opens the file on the system and returns an input stream to the caller. The caller reads the file's data from the input stream. The source file is on the system, accessed via FTP so the path separator character (if any) must be a forward slash.
        Overrides:
        get in class FTP
        Parameters:
        fileName - The file to get.
        Returns:
        An input stream to the file. The caller uses the input stream to read the data from the file. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        java.io.FileNotFoundException - If the name is a directory or the name is not found.
      • get

        public boolean get(java.lang.String sourceFileName,
                  java.lang.String targetFileName)
                    throws java.io.IOException,
                           java.io.FileNotFoundException
        Gets a file from the system. The source file is on the system, accessed via FTP so the path separator character (if any) must be a forward slash. The target file is on the client, accessed via java.io so the path separator character (if any) must be client specific.
        Overrides:
        get in class FTP
        Parameters:
        sourceFileName - The file to get on the system.
        targetFileName - The file on the target file system.
        Returns:
        true if the copy was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        java.io.FileNotFoundException - If the source file or the targe file cannot be accessed.
      • get

        public boolean get(java.lang.String sourceFileName,
                  java.io.File targetFile)
                    throws java.io.IOException,
                           java.io.FileNotFoundException
        Gets a file from the system. The source file is on the system, accessed via FTP so the path separator character (if any) must be a forward slash. The target file is an instance of Java.io.file.
        Overrides:
        get in class FTP
        Parameters:
        sourceFileName - The file to get on the system.
        targetFile - The file on the target file system.
        Returns:
        true if the copy was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
        java.io.FileNotFoundException - If the source file or the targe file cannot be accessed.
      • getCurrentDirectory

        public java.lang.String getCurrentDirectory()
                                             throws java.io.IOException
        Returns the current directory on the system.
        Overrides:
        getCurrentDirectory in class FTP
        Returns:
        The current directory on the system. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • getSaveFilePublicAuthority

        public java.lang.String getSaveFilePublicAuthority()
        Returns the public authority of save files created by this object. If this object detects putting a save file to the library file system of the system, it will first create the save file by sending a CRTSAVF command to the system. The method lets you set the *PUBLIC authority value on the CRTSAVF command. The default is *EXCLUDE.
        Returns:
        The authority granted to *PUBLIC.
      • getSystem

        public AS400 getSystem()
        Returns the name of the system. Null is returned if no system has been set.
        Returns:
        The name of the system to which this object connects.
      • issueCommand

        public java.lang.String issueCommand(java.lang.String cmd)
                                      throws java.io.IOException
        Sends a command to the system, returning the reply from the system.

        The command is not altered before sending it to the system, so it must be recognized by the system. Many FTP applications change commands so they are recognized by the system. For example, the command to get a list of files from the system is NLST, not ls. Many FTP applications convert ls to NLST before sending the command to the system. This method will not do the conversion.

        Overrides:
        issueCommand in class FTP
        Parameters:
        cmd - The command to send to the system.
        Returns:
        The reply to the command. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • ls

        public java.lang.String[] ls()
                              throws java.io.IOException
        Lists the contents of the current working directory. If the directory is empty, an empty list is returned.
        Overrides:
        ls in class FTP
        Returns:
        The contents of the directory as an array of Strings.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • ls

        public java.lang.String[] ls(java.lang.String criteria)
                              throws java.io.IOException
        Lists the contents of the current directory. If the directory is empty or no files match the search criteria, an empty list is returned.
        Overrides:
        ls in class FTP
        Parameters:
        criteria - The search criteria.
        Returns:
        The contents of the directory as an array of Strings.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • noop

        public boolean noop()
                     throws java.io.IOException
        Sends the NOOP (no operation) command to the system. This request is most useful to see if the connection to the system is still active
        Overrides:
        noop in class FTP
        Returns:
        true if the request was successful, false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • put

        public java.io.OutputStream put(java.lang.String fileName)
                                 throws java.io.IOException
        Starts the process of putting a file to the system. AS400FTP opens the data connection to the system, then opens the file on the system and returns an output stream to the caller. The caller then writes the file's data to the output stream.
        Overrides:
        put in class FTP
        Parameters:
        fileName - The file to put.
        Returns:
        An output stream to the file. The caller uses the output stream to write data to the file. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • put

        public boolean put(java.lang.String sourceFileName,
                  java.lang.String targetFileName)
                    throws java.io.IOException
        Puts a file to the system.
        Overrides:
        put in class FTP
        Parameters:
        sourceFileName - The file to put.
        targetFileName - The file on the system.
        Returns:
        true if the copy was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • put

        public boolean put(java.io.File sourceFileName,
                  java.lang.String targetFileName)
                    throws java.io.IOException
        Puts a file to the system.
        Overrides:
        put in class FTP
        Parameters:
        sourceFileName - The file to put.
        targetFileName - The file on the system.
        Returns:
        true if the copy was successful; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • pwd

        public java.lang.String pwd()
                             throws java.io.IOException
        Returns the current directory on the system. PWD is the ftp command Print Working Directory.
        Overrides:
        pwd in class FTP
        Returns:
        The current directory on the system. Null is returned if the connection to the system fails.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • setCurrentDirectory

        public boolean setCurrentDirectory(java.lang.String directory)
                                    throws java.io.IOException
        Sets the current directory on the system to directory. The method is the same as cd(). The message returned from the system is saved. Use getLastMessage() to retrieve it.
        Overrides:
        setCurrentDirectory in class FTP
        Parameters:
        directory - The current directory to set on the system.
        Returns:
        true if directory changed; false otherwise.
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • setDataTransferType

        public void setDataTransferType(int transferType)
                                 throws java.io.IOException
        Sets the data transfer type. Valid values are:

        If a connection does not already exist, a connection is made to the system. The message returned from the system is saved. Use getLastMessage() to retrieve it.

        Overrides:
        setDataTransferType in class FTP
        Parameters:
        transferType - ASCII or BINARY
        Throws:
        java.io.IOException - If an error occurs while communicating with the system.
      • setPassword

        public void setPassword(java.lang.String password)
        Calling setPassword() is valid only for FTP objects. An IllegalStateException is thrown if setPassword() is called on an AS400FTP object. SetPassword() is not needed because AS400FTP gets the password from the AS400 object.
        Overrides:
        setPassword in class FTP
        Parameters:
        password - The password for the user.
      • setSaveFilePublicAuthority

        public void setSaveFilePublicAuthority(java.lang.String publicAuthority)
                                        throws java.beans.PropertyVetoException
        Sets the public authority of save files created by this object. If this object detects putting a save file to the library file system of the system, it will first create the save file by sending a CRTSAVF command to the system. Through this method you can set the *PUBLIC authority used when sending the CRTSAVF command. The value is set only if the save file is created. The public authority of an existing save file is not changed.

        Valid values are:

        • *ALL
        • *CHANGE
        • *EXCLUDE
        • *LIBCRTAUT
        • *USE
        • authorization-list name.

        The default value is *EXCLUDE

        Parameters:
        publicAuthority - *PUBLIC authority.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setServer

        public void setServer(java.lang.String server)
                       throws java.beans.PropertyVetoException
        Calling setServer() is valid only for FTP objects. An IllegalStateException is thrown if setServer() is called on an AS400FTP object. SetServer() is not needed because AS400FTP gets the system name from the AS400 object.
        Overrides:
        setServer in class FTP
        Parameters:
        server - The name of the system to which this object connects.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setSystem

        public void setSystem(AS400 system)
                       throws java.beans.PropertyVetoException
        Sets the name of the system. The system name cannot be changed once a connection is made to the system.
        Parameters:
        system - The name of the system to which this object connects.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.
      • setUser

        public void setUser(java.lang.String user)
                     throws java.beans.PropertyVetoException
        Calling setUser() is valid only for FTP objects. An IllegalStateException is thrown if setUser() is called on an AS400FTP object. SetUser() is not needed because AS400FTP gets the userid from the AS400 object.
        Overrides:
        setUser in class FTP
        Parameters:
        user - The user identifier used when connecting to the system.
        Throws:
        java.beans.PropertyVetoException - If the change is vetoed.