0

I could not copy the file with spaces in file name using ssh2_scp_recv() function.This is the filename testfile-03_23_15 11 02 AM.csv which actually stored in server.
my code is here

if ($file == "testfile-03_23_15 11 02 AM.csv"){

    if(!ssh2_scp_recv($connection,$remoteDir .$file, $localDir . $file)){
        echo "Could not download: ", $remoteDir, $file, "\n";
    }
}

Please help me if you know. Thanks.

Kenster
  • 23,465
  • 21
  • 80
  • 106
Benson KP
  • 1
  • 3

2 Answers2

1

With phpseclib:

<?php
include 'phpseclib/Net/SSH2.php';
include 'phpseclib/Net/SCP.php';

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('bad login');
}
$scp = new Net_SCP($ssh);
$scp->get('file name with spaces');
sparkita
  • 11
  • 1
0

Try this one:

 ssh2_scp_recv($connection,"\"".$remote_file_name."\"",$local_path."/".$remote_file_name); 

Source: php.net

It says: Trying to get a remote file with spaces in its name? Never forget to use quotes in the remote filename, but never in the local one.

B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
  • Thanks for reply.. :) I tried this but it did not work.. My updated code is here if ($file == "testfile-03_23_15 11 02 AM.csv"){ $remote = $remoteDir . $file; if(!ssh2_scp_recv($connection,$remoteDir ."\"".$file."\"", $localDir . $file)){ echo "Could not download: ", $remoteDir, $file, "\n"; } } Any other solutions.. – Benson KP May 12 '15 at 17:28