• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Using FTP to Poll for File

    April 6, 2005 Hey, David

    I am moving data between an iSeries system and several Unix systems. I pull the files over manually using FTP and then use the Copy from Import File (CPYFRMIMPF) to copy the records to a database file. After processing is done, I send the files back to the Unix system.

    The biggest “hole” in the process is that there is no automated way to bring over the files from the FTP server onto the iSeries. I would like to have a polling process that would go through a list, check for new files to process, automatically run the FTP GET, and kick off a batch job to process the file. Do you have anything like that?

    –Mark

    After receiving Mark’s initial email, I found out some more details that helped to shape the solution described below. Those details helped me understand why a commercial solution wasn’t an option and that a Java-based solution might have advantages in Mark’s mixed system environment.

    What I sent Mark was a program that checks for incoming files residing on other systems and pulls those files down to the local system. I named that program FtpPoll and if you are interested, you can download the source and follow along while I describe how this program works.

    The purpose of the FtpPoll program is to poll any number of servers checking for files to retrieve. When a file is found, a thread is started that retrieves the file to the local server via FTP. After downloading the file to the local server, the FtpPoll program deletes the file from the remote server. This process repeats at regular intervals until a shutdown request arrives in the control data queue.

    The main processing occurs in the pollFile method. That method checks for files to download and then waits on a data queue for the number of seconds specified in the POLL_INTERVAL_SECONDS variable before checking again. If an entry arrives on the data queue, the polling process ends.

    The addFtpFile method adds remote files to the list of files that the program polls. An inner class of FtpPoll named FtpFile defines file attributes like the FTP URL, user, password, remote file name, and local file name and is passed to addFtpFile. For testing purposes, the main method creates an FtpFile if five parameters representing FTP URL, User, Password, file, and the local file name to download to and adds it to the ftpFiles set. Of course, in most cases, you would load the ftpFiles array from a database or hard-code the files in the main method. Since the ftpFiles variable is a java.util.Set, duplicates are not allowed based on the compareTo method in FtpFile.

    When a file is located on a remote server, the pollFile method calls the retrieveFile method. The first thing the retrieveFile method does is start a new thread to perform the actual download. This allows control to return to the pollFile method immediately. When the thread starts, a sending flag is set to “true” to prevent simultaneous retrieval requests for the same file. The file is then retrieved to the local server and then the remote file is deleted.


    You will need to do some setup before you can run this program on your iSeries system. First, if you are not currently running production Java programs on your system, I recommend that you get your system up to date on PTFs. That means you should load the latest cumulative and group PTF packages. If possible, you should also make sure you are using version 1.4 of the Java Development Kit on your system. You can verify typing in GO LICPGM from an OS/400 command line. Select option 10 to see if licensed program 5722JV1 option 6 (the JDK 1.4) is installed. If it is not installed, do so by selecting option 11 and placing a 1 next to 5722JV1 option 6.

    After verifying that your JDK and PTFs are up to date, save FtpPoll.java in an IFS directory and start Qshell using the QSH command. The comments at the top of the FtpPoll.java source describe the commands you need to use to set your class path, compile, and run FtpPoll. Before testing on live data, remember that the remote file is deleted after it is downloaded.

    I hope FtpPoll gets you off to a good start. In its current state, it is pretty basic. But I am here to help if you run into trouble adapting it to your environment or need to add additional features.

    –David

    Click here to contact David Morris by e-mail.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    NetManage Streamlines Mobile Access to Host Data SecureZIP for iSeries Now Available from PKWARE

    Leave a Reply Cancel reply

Volume 5, Number 14 -- April 6, 2005
THIS ISSUE
SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
Guild Companies

Table of Contents

  • Using FTP to Poll for File
  • Yet Another Way to Build a Tab-Delimited File
  • Admin Alert: Using OS/400 Prestart Jobs for Repetitious Server Processing

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • The Turning Point For Power Systems Is Here, And Now
  • How IBM i Users Can Compete In The Digital Era With Composable Commerce
  • IBM Streamlines Data Migration With New Partition Mirror Tech
  • Profound Logic Adds MCP To IBM i AI Tool
  • IBM i PTF Guide, Volume 27, Number 29
  • Power11 Entry Machines: The Power S1124 And Power L1124
  • BRMS Isn’t The Only Backup Product With A Security Problem
  • Guru: A Faster Way To Sign A JWT
  • Maxis Adds IBM i Support To Database Modernization Tool
  • IBM i PTF Guide, Volume 27, Number 28

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle