FTP class

The FTP class provides a programmable interface to FTP functions. You no longer have to use java.runtime.exec() or tell your users to run FTP commands in a separate application. That is, you can program FTP functions directly into your application. So, from within your program, you can do the following:

For example, with the FTP class, you can copy a set of files from a directory on a server:

     FTP client = new FTP("myServer", "myUID", "myPWD");
     client.cd("/myDir");
     client.setDataTransferType(FTP.BINARY);
     String [] entries = client.ls();

     for (int i = 0; i < entries.length; i++)
     {
       System.out.println("Copying " + entries[i]);
       try
       {
         client.get(entries[i], "c:\\ftptest\\" + entries[i]);
       }
       catch (Exception e)
       {
         System.out.println("  copy failed, likely this is a directory");
       }
     }

     client.disconnect();

FTP is a generic interface that works with many different FTP servers. Therefore, it is up to the programmer to match the semantics of the server.

FTP subclass

While the FTP class is a generic FTP interface, the AS400FTP subclass is written specifically for the FTP server on the server. That is, it understands the semantics of the FTP server on the iSeries or AS/400e server, so the programmer doesn't have to. For example, this class understands the various steps needed to transfer a save file to the server and performs these steps automatically. AS400FTP also ties into the security facilities of the IBM Toolbox for Java. As with other IBM Toolbox for Java classes, AS400FTP depends on the AS400 object for system name, user ID, and password.

The following example puts a save file to the server. 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 steps automatically.

 AS400 system = new AS400();
 AS400FTP ftp = new AS400FTP(system);
 ftp.put("myData.savf", "/QSYS.LIB/MYLIB.LIB/MYDATA.SAVF");