could not copy file name with space in scp ssh

橙三吉。 提交于 2021-02-08 11:21:28

问题


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.


回答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');



回答2:


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.



来源:https://stackoverflow.com/questions/30194011/could-not-copy-file-name-with-space-in-scp-ssh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!