首页 文章

尝试SSL连接时PHP的FTP功能

提问于
浏览
2

我已经做了所有可能的连接来验证FTP服务器是否正常工作,甚至可以使用file_put_contents()来上传文件,但PHP的FTP功能在尝试SSL连接时对我不起作用 . 服务器配置为不允许非SSL连接,因此没有回退 . 没关系,一切仍然有效,但我真的想用ftp_ssl_connect()和ftp_login()来工作!

看这个例子:

<?php

$username    = 'someuser';
$password    = 'SeCrEtPassWd';
$hostname    = '192.168.1.10';
$filename      = 'whatever.txt';
$string_data  = 'This is the text content of the file. Pretty fancy eh?';


// USE file_put_contents W/ stream_context_create - WORKS !!!!
$url = 'ftps://' . $username . ':' . $password . '@' . $hostname . '/';
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create( $opts );
file_put_contents( $url . $filename, $string_data, 0, $context );

// END of code that works -----------------------------------

// USE PHP's FTP functions - DOES NOT WORK !!!
$conn_id = @ftp_ssl_connect( $hostname );
$login_result = ftp_login( $conn_id, $username, $password );
ftp_put( $conn_id, $filename, $filename, FTP_ASCII );
ftp_close( $conn_id );

// END of code that does not work ---------------------------

/*
****ERRORS PERTAINING TO THE PROBLEM ----------------------------****

Warning: ftp_login() [function.ftp-login]: SSL/TLS handshake failed in C:\xampp\htdocs\script-library\ftps.php on line 20
Warning: ftp_login() [function.ftp-login]: Proceed with negotiation. in C:\xampp\htdocs\script-library\ftps.php on line 20
*/

这是PHP中的错误吗?我只是不明白为什么其他一切都有效,而不是PHP FTP功能 . 我的问题是我真的需要能够列出远程服务器上的文件,因为我不想覆盖它们 . 我想将文件重命名为不存在的东西 .

2 回答

  • 0

    您可以使用phpseclib来做到这一点,它对我来说非常适合:http://phpseclib.sourceforge.net/

  • 2

    我需要:

    ftp_pasv($conn_id, true);
    

    登录后让我的工作 .

相关问题