dongxun1978 2014-04-09 15:33
浏览 110
已采纳

使用ftp和php脚本将图像上传到服务器时出错,在ftp_put()登录时出错

I have a script written in php which basically uploads images to a server. I'm uploading this script onto my server using an ftp account credentials. However when I try to access it, it gives me login error. Here's the error log:

[09-Apr-2014 19:00:01 Asia/Kolkata] PHP Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server. in /home/gameeon/public_html/jts/local_upload.php on line 8 [09-Apr-2014 19:01:33 Asia/Kolkata] PHP Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server. in /home/gameeon/public_html/jts/local_upload.php on line 8 [09-Apr-2014 19:01:55 Asia/Kolkata] PHP Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server. in /home/gameeon/public_html/jts/local_upload.php on line 8 [09-Apr-2014 19:02:21 Asia/Kolkata] PHP Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server. in /home/gameeon/public_html/jts/local_upload.php on line 8 [09-Apr-2014 19:03:59 Asia/Kolkata] PHP Warning: ftp_login(): Sorry, cleartext sessions are not accepted on this server. in /home/gameeon/public_html/jts/local_upload.php on line 8

My code is as follows:

<?php
// connect and login to FTP server
$ftp_server = "ftp.gameeon.in"; // enter the ftp host name
$ftp_username = "temp@gameeon.in"; // put your ftp user name
$ftp_userpass = "********"; // put your ftp password

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

/// put the path of your image folder in your remote server i.e:
$ftp_upload_path="public_html/img/";

/// put the path of your image folder in your local machine:
$files = glob("E:/upload_images/*.*");

 foreach($files as $fl)
 {

     $fl_arr = explode("/",$fl); 
     $cn=count($fl_arr);
     $num=$cn-1;
     $file=$fl_arr[$num];

     // upload file
     // $fl = full path of localimages

     if (ftp_put($ftp_conn, $ftp_upload_path.$file,$fl, FTP_ASCII))
     {
         echo "Successfully uploaded $file. <br/>";
     }
     else
     {
         echo "Error uploading $file.<br/>";
     }
     sleep(3); /// pausing the code for 3 secs before next upload

 }

 // close connection
 ftp_close($ftp_conn);
?>

I'm getting an error on this line no. 8 which is:

$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
  • 写回答

1条回答 默认 最新

  • doudao3170 2014-04-09 17:01
    关注

    You need to use ftp_ssl_connect() function instead of ftp_connect() because server is using Explicit TLS/SSL

    Try this:

    $ftp_conn = ftp_ssl_connect($ftp_server)
                or die("Could not connect to $ftp_server");
    

    If you are working on localhost you may encounter error saying

    ftp_put(): I won't open a connection to 192...* something..

    Then you have to use the ftp_pasv function.

    As of docs:

    In passive mode, data connections are initiated by the client, rather than by the server. It may be needed if the client is behind firewall.

    In your case yes you need to use it you are using Explicit TLS/SSL just before your loop add this:

    ftp_pasv($ftp_conn, true);
    

    Also set your path public_html/img/ to /img/ or whatever directory exists:

    $ftp_upload_path = "/img/";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能