我正在尝试在PHP中建立FTP SSL连接。我使用ftp_connect()很好,工作很棒。一旦我尝试使用ftp_ssl_connect(),我就会得到以下错误:
致命错误:调用未定义函数ftp_ssl_connect()
我确实在PHP扩展中打开了openssl扩展。我不知道还能做什么,作为搜索谷歌,没有什么可以做的,使这个函数调用工作。有人知道我什么时候丢失了什么吗?或者检查一下是否需要在我的wampserver上安装其他的东西?
下面是我正在使用的php代码:
$conn_id = ftp_ssl_connect($ftp_server);
$ftp_user_name = "username";
$ftp_user_pass = "password";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}显然,它没有越过第一行,因为它说ftp_ssl_connect()是一个未定义的函数。
发布于 2016-01-29 13:28:34
发布于 2020-05-08 16:04:21
PHP7.1.12 CentOS
我自己构建php。
/usr/local/php71/bin/php -r "ftp_ssl_connect('server1.example.com');"
PHP Fatal error: Uncaught Error: Call to undefined function ftp_ssl_connect() in Command line code:1决心:
# /root/php-7.1.12/ is php source dir
cd /root/php-7.1.12/ext/ftp/
# /usr/local/php71/ is php dir
/usr/local/php71/bin/phpize
# the param --with-openssl-dir is very important
./configure --with-php-config=/usr/local/php71/bin/php-config --with-openssl-dir
make
make install
vim /usr/local/php71/lib/php.ini
# add last line
extension=ftp.so
service php-fpm reload核对:
# method 1
/usr/local/php71/bin/php -r "phpinfo();" | grep FTP
FTP support => enabled
FTPS support => enabled
# method 2
/usr/local/php71/bin/php -r "ftp_ssl_connect('server1.example.com');"
PHP Warning: ftp_ssl_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1完成了!
https://stackoverflow.com/questions/35085677
复制相似问题