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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料