Search code examples
phpftpibm-midrange

How can i pass the namefmt parameter in a php ftp connection?


I need to connect via FTP to an as400 server. The connection necessarily requires the NAMEFMT parameter to write. How is it possible to insert the parameter in php ftp connection code?

Thanks


Solution

  • use ftp_site to send the namefmt command.

    $ftp = ftp_connect('serverurl.com');
    ftp_login($ftp, 'user', 'pass');
    ftp_site( $ftp, "namefmt 1");
    ftp_chdir( $ftp, "/home/steve");
    
    // get contents of the current directory
    $contents = ftp_nlist($ftp, ".");
    
    // write directory listing to stdout
    echo "<pre>";
    foreach( $contents as $item )
    {
      echo "$item\n";
    }
    echo "</pre>";
    
    // change namefmt to 0.
    ftp_chdir( $ftp, "/qsys.lib/qgpl.lib");
    ftp_site( $ftp, "namefmt 0");
    
    // get srcmbr named PROOF in QGPL/QRPGLESRC
    echo "<pre>";
    $result = ftp_get($ftp, "php://output", "qgpl/qrpglesrc.proof", FTP_ASCII );
    echo "</pre>" ;
    ftp_close( $ftp ) ;