dongwubao4785 2012-03-19 07:48
浏览 73
已采纳

将文件发送到linux服务器

I'm kind of new to php, and I'm trying to send a file through ftp to a computer that's runs "Centos 6" (Linux server). My code is :

<?php
$ftp_server = "XX.XXX.XXX.XXX";
$ftp_user = "user";
$ftp_pass = "password";

//set up a connection or die
 $conn_id = ftp_connect($ftp_server,22) or die("Couldn't connect to $ftp_server"); 
 ftp_pasv($conn_id, true);

 //try to login
 if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server
";
 } else {
    echo "Couldn't connect as $ftp_user
";
 }

  //close the connection
 ftp_close($conn_id);  
?>

I'm running the latest versions of Mysql and Apache, and also disable the firewall in the server. I can get to the server with Filezilla but only if I use port 22.

  • 写回答

2条回答 默认 最新

  • dongyan1974 2012-03-26 08:14
    关注

    This is how i did it:

    <?php
    include('Net/SFTP.php');
    
    $sftp = new Net_SFTP('xx.xxx.xxx.xxx');
    if (!$sftp->login('user', 'pass')) {
        exit('Login Failed');
    }
    
    //Write to a text file
    $sftp->put('destinationInServer/filename', file_get_contents('Source/filename'));
    echo "Success";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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