FTP Means ‘First Try Pinging’
April 4, 2007 Cletus the Codeslinger
File Transfer Protocol, or FTP, was obviously designed by academics. While academics are OK people (after all, my editor, Ted Holt, is a part-time instructor at a community college), they are not familiar with what goes on at the factory (like the one where I work full-time). That means that making FTP (and other Unix-type applications) work dependably in an automated environment can be a challenge. Here’s a tip that can help. FTP was intended to work this way: a human types a command into a computer. The computer responds. The human types another command. The computer responds. Etc. Etc. And so forth. Ad nauseum. That’s all well and good, but who wants to crawl out of bed at 3 a.m. every day to send a file to somebody? Unix has a “solution” to this problem–scripting. Put the FTP commands into a text file and tell the computer to read them and run them. While you’re at it, tell the computer to store the responses from the remote system in a text file. And whatever you do, don’t let the script read those responses, determine if an FTP command succeeded or failed, and continue accordingly, as a human would. It would help if the wienies who design this junk would add some useful features to FTP, such as the ability to check a return code and to make decisions accordingly. But I’m not holding my breath. Academicians are too busy publishing (to keep from perishing) and applying for grants. Seeing as we’re saddled with crippleware, let’s do the best we can do. One of the most common reasons FTP fails is that the remote server is down. Use the Verify TCP/IP Connection (PING or VFYTCPCNN) command to determine whether the server is up or not. This is really easy on my robust System i computer, because some practical someone at IBM thoughtfully provided a way for PING to send an escape message. It’s in the second positional value of the MSGMODE parameter. (This is not your standard ping.) In the following code example, the PING command tests to see if the server is up. If the PING fails, the system sends escape message TPC3210. dcl &Server *char 50 dcl &ServerIsUp *lgl chgvar &ServerIsUp '1' ping rmtsys(&Server) msgmode(*quiet *escape) monmsg tcp0000 exec(chgvar &ServerIsUp '0') if (*not &ServerIsUp) do /* whatever */ return enddo clrpfm ftplog mbr(SomeMbr) ovrdbf file(input) tofile(ftpscripts) mbr(SomeMbr) ovrdbf file(output) tofile(ftplog) mbr(SomeMbr) ftp rmtsys(&Server) dltovr *all monmsg cpf0000 I look forward to the day when everybody uses Unix. Instead of having just a few IT people at the factory, we’ll need an army, and that means we’ll all have jobs. Yes, Unix is truly the full-employment operating system.
|