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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?