• 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
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    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

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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