Script Control of sftp

Alan Little openssh at holotech.net
Sat Oct 18 04:12:37 EST 2003


I am trying to conduct a full sftp session using the proc_open()
function of PHP:

http://www.php.net/manual/en/function.proc-open.php

Once I get past the authentication stage, everything works fine: the
script is able to write to sftp's stdin and capture its stdout.
However, during the auth stage, these are apparently bypassed somehow,
and IO takes place directly with the terminal. That is, the password
prompt appears on the screen, and the password is accepted directly
from the keyboard, while the password submitted by the script is
ignored. Any ideas why, and/or how I can control the IO through the
auth stage? Here is my code:

#!/usr/www/users/holotech/cgi-bin/php4.cgi
<?php
  $descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("file", "/tmp/error-output.txt", "a")
  );

  $Server = "myserver.pair.com";
  $User   = "holotech";
  $Pass   = "########";

  $sftp   = "/usr/bin/sftp";

  $process = proc_open(
    "$sftp $User@$Server",
    $descriptorspec,
    $pipes
  );

  if (is_resource($process)) {
    fwrite($pipes[0], $Password."\n");
    fclose($pipes[0]);

    while(!feof($pipes[1])) {
      echo fgets($pipes[1], 1024);
    }
    fclose($pipes[1]);
    $return_value = proc_close($process);

    echo "\ncommand returned $return_value\n";
  }
?>

-- 
Alan Little
Holotech Enterprises




More information about the openssh-unix-dev mailing list