-1

I have a folder which has 2 files.When I am running the below code, it works for the first loop but second time onwards it fails with the warning as - Warning: ssh2_scp_send(): Failure creating remote file: Unexpected channel close in /var/www/html/..../newCheck.php

Also i am running this on a Linux platform and trying to transfer file to Windows(destination).

foreach($results as $key => $val)   {
        if(!is_dir($val))   {
            $valArr =   explode('/',$val);
            $filename   =   array_pop($valArr);
            ssh2_scp_send($conn,'/var/www/html/Portal/'.$filename, 'D:/'.$filename, 0644);

        }
    }

Any Idea?

M3ghana
  • 1,231
  • 1
  • 9
  • 19

1 Answers1

0

I could resolve the issue on my own - Here is the solution -

foreach($results as $key => $val)   {
        if(!is_dir($val))   {
            $valArr =   explode('/',$val);
            $filename   =   array_pop($valArr);

            $conn = ssh2_connect('x.x.x.x', 22);  
            ssh2_auth_password($conn, 'username', 'password');  
            ssh2_scp_send($conn,'/var/www/html/Portal/'.$filename, 'D:/'.$filename, 0644);
            ssh2_exec($conn, 'exit');
        }
}
M3ghana
  • 1,231
  • 1
  • 9
  • 19