• 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
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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