Calling FTP RMTSYS from ODBC in PHP?

80 pts.
Tags:
iSeries
ODBC
PHP
QCMDEXC
RMTSYS
Hello everyone. This is an interesting problem. I have this code and I want to call FTP RMTSYS('') command through ODBC from PHP. Nothing happens. When I issue the command in DBVisualizer: CALL QSYS.QCMDEXC('FTP RMTSYS(iSeries_SERVER)',  0000000020.00000); I get this error: Program contains commands only valid when run interactively.      Application error.  CPD0772 unmonitored by QSNDEVQ at statement     0000000001, instruction X'0000'.                                FTP client exit error.                                        Now, this command can be run in batch mode when in CL or RPG-ILE programme. Can it be run this way, from ODBC in PHP? The following code works until it reaches the command in question. Any help or hint would be appreciated :) <?php /* Starting PHP session */     session_start(); /* Declaring varialbes */     $_SESSION[server]= 'iSeries_SERVER';     $_SESSION[user]= 'username';      $_SESSION= 'password';           $up = "up";     $lib = "lib";     $libu = "libu";     $lpar = "lpar";      $table = 'library.ftpin'; /* Creating connection towards iSeries server */     $conn = odbc_connect($_SESSION[server],$_SESSION[user],$_SESSION);     if ($conn == false) {     echo " Not connected to database ! ";     }     else     {     echo " Connected to database ! ";     };      /* Creating INPUT file for FTP */          $create_ftpin = "create table library.ftpin (rcdfmt char(300))";         $crttbl_res = odbc_do($conn, $create_ftpin);      /* Creating OUTPUT file for FTP */          $create_ftpout = "create table library.ftpout (rcdfmt char(300))";         $crttbl_res = odbc_do($conn, $create_ftpout);           /* Inserting values into INPUT file for FTP */          $insert = "insert into library.ftpin values     'library library',     'bin',     'namefmt 1',     'quote rcmd CRTLIB LIB(TEMPX)',     'cd tempx.lib',     'lcd library.lib',     'put transfer.file',     'quote rcmd RSTOBJ obj(*all) savlib(lib) dev(*savf) savf(tempx/transfer) mbropt(*all) alwobjdif(*all) rstlib(TEMPXX)',     'quote rcmd RMVLIBLE LIB(TEMPX)',     'quote rcmd DLTLIB LIB(TEMPX)',     'close',     'quit'         ";          $insrt_res = odbc_do($conn, $insert);      /* Calling subsequent commands from PHP through ODBC */              $qry1="CALL QSYS.QCMDEXC('CRTSAVF FILE(library/TRANSFER)',  0000000029.00000)";     $stmt1 = odbc_prepare($conn, $qry1);     $result1 = odbc_execute($stmt1);          $qry2="CALL QSYS.QCMDEXC('CRTSRCPF FILE(library/ftpout) MBR(ftpout)',  0000000063.00000)";              $qry2 = "CALL QSYS.QCMDEXC ('SAVOBJ OBJ(*ALL) LIB(library) DEV(*SAVF) OBJTYPE(*ALL) SAVF(library/TRANSFER) SAVACT(*SYNCLIB)', 0000000092.00000)";         $stmt2 = odbc_prepare($conn, $qry2);     $result2 = odbc_execute($stmt2);          $qry3 = "CALL QSYS.QCMDEXC('OVRDBF FILE(INPUT) TOFILE(library/ftpin)',  0000000039.00000)";         $stmt3 = odbc_prepare($conn, $qry3);     $result3 = odbc_execute($stmt3);              $qry4 = "CALL QSYS.QCMDEXC('OVRDBF FILE(OUTPUT) TOFILE(library/ftpout)',  0000000041.00000)";         $stmt4 = odbc_prepare($conn, $qry4);     $result4 = odbc_execute($stmt4); /* Everything works until here! */          $qry5 = "CALL QSYS.QCMDEXC('FTP RMTSYS(ASUDOT21)',  0000000020.00000)";         $stmt5 = odbc_prepare($conn, $qry5);     $result5 = odbc_execute($stmt5);                  $qry6 = "CALL QSYS.QCMDEXC('DLTOVR FILE(INPUT OUTPUT)',  0000000024.00000)";         $stmt6 = odbc_prepare($conn, $qry6);     $result6 = odbc_execute($stmt6);     $qry8="CALL QSYS.QCMDEXC('DSPF FILE(library/ftpout)',  0000000063.00000)";              $qry9="CALL QSYS.QCMDEXC('DLTF FILE(library/ftpout)',  0000000063.00000)";              $qry10="CALL QSYS.QCMDEXC('CLRLIB library',  0000000063.00000)";                        odbc_close($conn);     session_destroy();         ?>

Software/Hardware used:
AS400, iSeries, PHP, ODBC
ASKED: December 20, 2010  11:35 AM
UPDATED: December 28, 2010  8:52 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Please run DSPCMD FTP and post the "Where allowed to run" section here. You don't show us the i5/OS version you're running, so I can't tell if you'll run into a command proxy chain. If you do, then run DSPCMD <proxyLib>/FTP instead. It's possible that your FTP command allows execution in a program in batch but not as a batch command. Also, I wouldn't run the OVRDBF commands separately from the FTP command. There's no guarantee that they'll run in the same job nor that the override will still be in effect when the FTP command runs. Both should be in a program together. And AFAIK, the FTP command is not threadsafe up through at least V7R1. You might run into unpredictable results trying to run it this way. Tom
    125,585 pointsBadges:
    report
  • Avrelivs
    Hi Tom, thank you for the answer, and, yes, sorry I didn't post the system OS version it is V6R1M0. I do agree with you on OVRDBF, if nothing else I think OVRDBF and FTP command maybe should run in the same job. But, as FTP command can be run in batch mode as well as interactive, I hope we could find a way to do so this way. :) And on DSPCMD FTP i get this: Display Command Information Command . . . . . . . : FTP Library . . . . . . . : QSYS Target command . . . . . . . . . . . . : FTP Library . . . . . . . . . . . . . . : QTCP Text . . . . . . . . . . . . . . . . . : Start TCP/IP File Transfer Current proxy chain . . . . . . . . . : QSYS/FTP QTCP/FTP
    80 pointsBadges:
    report
  • Avrelivs
    OVRDBF command and FTP Command should run in same job else OVRDBF will have no effect. And yes FTP command can be run interactively and as well as in Batch
    0 pointsBadges:
    report
  • TomLiotta
    Current proxy chain . . . . . . . . . : QSYS/FTP QTCP/FTP On V5R4 and later, commands can be "proxies" instead of being "duplicates". That is, you can copy a command with CRTPRXCMD instead of with CRTDUPOBJ. A proxy command is more like a symbolic link back to the original command than a new object that is a copy of the old one. The 'Current proxy chain' above shows that the real FTP command is in QTCP, not QSYS. So you run DSPCMD QTCP/FTP to locate the “Where allowed to run” section. There seem to be two likely possibilities. First, the “Where allowed to run” attribute allows your FTP command to be run in batch if it's in a program. Second, the OVRDBFs are not in effect when the FTP runs, so it tries to communicate with a terminal session. Other possibilities might exist, but we should try to make sure that those two are eliminated before digging deeper. And just in case, you probably should run WRKOBJ *ALL/FTP just to make certain that no other versions of the command exist in any other libraries. Tom
    125,585 pointsBadges:
    report
  • Avrelivs
    @Ddaswani I'll try to rearrange my code so OVRDBF's are in the same job as FTP RMTSYS. @TimiLiotta As for "where allowed to run" part of the FTP command, this is what it says: Where allowed to run . . . . . . . . . : *IMOD *BMOD *IREXX *BREXX *BPGM *IPGM *EXEC *INTERACT *BATCH Also, mode(s) in which valid: Mode(s) in which valid . . . . . . . . : *PROD *DEBUG *SERVICE Or maybe this setings could be of the interest: Enabled for graphical user interface . : *YES Threadsafe . . . . . . . . . . . . . . : *NO Multithreaded job action . . . . . . . : *SYSVAL I'm not sure if setting this could help. I'll try to do some changes and I'll get beck to you with some results :)
    80 pointsBadges:
    report
  • Splat
    I think the problem has to do with the lack of overrides in effect for the INPUT and OUTPUT files. We do use FTP in batch programs & haven't had any problems.
    6,255 pointsBadges:
    report
  • TomLiotta
    If there are no other FTP commands on the system, then the first possibility to handle is that the overrides are not in effect. The OVRDBF and FTP commands should be codded into a CL program. Then the program can be called through QCMDEXC. If that is successful, then the problem is probably confirmed to be with the overrides. If it is not successful, then the CL program should posted here along with the joblog that shows the running of the program. You include a DSPJOBLOG command after the FTP command in the CL program to ensure that a joblog is spooled. If the FTP fails and causes the program to fail before the DSPJOG command can run, you should include a MONMSG for the FTP error to make certain that the program continues. Tom
    125,585 pointsBadges:
    report
  • Splat
    Tom, we've got FTP running from inside an RPG/ILE program - the OVRDBF commands and the FTP command being executed using the QCAPCMD API. The override scope is *CALLLVL, but that's about the only thing slightly out of the ordinary.
    6,255 pointsBadges:
    report
  • TomLiotta
    we’ve got FTP running from inside an RPG/ILE program That should be fine because the RPG program is guaranteed to execute the overrides and the FTP command in the same job. But PHP will be interpreted. I don't currently have a PHP setup to test, so I can't tell if the calls to QCMDEXC will always be executed in the same job or if they'll be handed off to different BCI jobs or if they'll be executed in different threads or what. The CPD0772 error suggests that the FTP is being run as an *INTERACTIVE command, which suggests that FTP is trying to open a terminal session for the input script and for any output. The OVRDBFs look okay (though I can't tell because I don't know if they're really valid on that system). If you simply submit a FTP command by itself to batch, you should see the same CPD0772 error. The text of the message is probably a little misleading in this case, but the meaning is appropriate. Execute the commands within a single compiled program, such as your RPG, and it should work. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following