简体   繁体   中英

php ssh2_scp_send inside a for-loop fails for the second time onwards

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?

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');
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM