Script Control of sftp

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

I am trying to conduct a full sftp session using the proc_open()
function of 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:

  $descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("file", "/tmp/error-output.txt", "a")

  $Server = "";
  $User   = "holotech";
  $Pass   = "########";

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

  $process = proc_open(
    "$sftp $User@$Server",

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

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

    echo "\ncommand returned $return_value\n";

Alan Little
Holotech Enterprises

More information about the openssh-unix-dev mailing list