【问题标题】:PHP script copy file from webserver to standalone mac osxPHP脚本将文件从网络服务器复制到独立的mac osx
【发布时间】:2016-04-10 09:40:12
【问题描述】:

我正在尝试连接到 mac osx。 但我收到错误。 我怎么能把文件复制到这个mac?

我还有以下:

afp://192.xxx.x.x

smb://192.xxx.x.x

name@192.xxx.x.x

错误:

警告:ssh2_connect():无法连接到端口 22 上的 192.xxx.xx 在第 7 行的 /home/test.php 中

警告:ssh2_connect(): Unable to connect to 192.xxx.x.x in /home/test.php 第 7 行失败:无法建立连接

PHP 脚本:

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22

if(!($con = ssh2_connect("192.xxx.xx.xx", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "", "")) {
    echo "fail: unable to authenticate\n";
} else {
    // allright, we're in!
    echo "okay: logged in...\n";

    // execute a command
    if (!($stream = ssh2_exec($con, "ls -al" ))) {
    echo 123;
    echo "fail: unable to execute command\n";
    } else {

    // collect returning data from command
    stream_set_blocking($stream, true);
    $data = "";
    while ($buf = fread($stream,4096)) {
        $data .= $buf;
    }
    ssh2_exec($con, 'ls -al; echo "__COMMAND_FINISHED__"' );
    fclose($stream);
    }
}
}

【问题讨论】:

  • 看起来端口 22 没有为您尝试连接的计算机上的入站连接打开。
  • @MarkChorley,我如何在 Mac 上启用此功能?
  • 或者你没有运行 ssh 守护进程。去谷歌上查询?这不是一个真正的编程问题,可能特定于您的操作系统版本

标签: php macos ssh


【解决方案1】:

我们向 wright 开放 22 端口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-30
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多