dpthuyh1678 2016-01-28 13:44
浏览 209
已采纳

php中的ftp_connect失败

I want to connect to a remote server whose ip adress is xx.xxx.xxx.xx to later write on a file on it. Here my php code:

<?php
$remote_file = 'test_remote.txt';
$file = 'test.txt';

$conn_id = ftp_connect('xx.xxx.xxx.xx') or die("Could not connect")
$login_result = ftp_login($conn_id, 'name', 'passwd');

if (ftp_fput($conn_id, $remote_file, $file, FTP_ASCII)) {
    echo "ok";
} else {
    echo "failed";
}

ftp_close($conn_id);
?>

I get the error "Could not connect"....

If I do

ssh name@xx.xxx.xxx.xx and entered the password it works fine. What is the problem?

Thanks

  • 写回答

1条回答 默认 最新

  • dptrmt4366 2016-01-28 14:30
    关注

    You need to install ssh ftp extension, you can view the download documentation here

    When you have installed it and its working properly(remember to restart your webserver after installation), you can do the following:

    $connection = ssh2_connect('ip/address', 'port');
    if(ssh2_auth_password($connection, 'username', 'password') {
            $sftp = ssh2_sftp($connection);
            $fileStream = fopen("ssh2.sftp://" . $sftp . "pathToFile", 'w');
            //Write your data with fwrite($fileStream, $data)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建