duanqiang6501 2016-02-08 10:44
浏览 55

使用PHP设置SSH连接和SFTP

I'm trying to set up a ssh connection, and later a sftp connection to transfer file via FTP to my server. I have used FileZilla to upload files successfully before.

These are my login terminal command and FileZilla login information:

ssh b0xxxxx@linux7.aa.bb.cc.dd
Host: sftp://linux7.aa.bb.cc.dd
Username: b0xx
Port: 22

Here is my php code:

<?php
    $ftp_server = "b0xx@linux7.aa.bb.cc.dd";
    $ftp_port = 22; 
    $ftp_user = "b0xx";
    $ftp_pass = "##";
    $connection = ssh2_connect($ftp_server, $ftp_port);
    echo "Successful!
";
    if (ssh2_auth_password($connection, $ftp_user, $ftp_pass)) {
      echo "Successful
";
    } else {
      die ('Failed...');
    }
    $sftp = ssh2_sftp($connection);
    ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);

?>

Question 1: Can I just use ftp functions to upload/download file from my server? Or do I must set up ssh?

Question 2: When I execute the code, the website only displays

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

which means that the code does not execute connection successfully. Does anyone know the cause of the bug?

Very much appreciate the help.

  • 写回答

2条回答 默认 最新

  • dongzaliang4492 2016-02-08 10:54
    关注

    Seems SSH2 PECL extension is not installed. Install the extension and then try your code.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器