NickC217
NickC217

Reputation: 226

Fatal error: Call to undefined function ftp_ssl_connect()

I am trying to set up FTP SSL connection in PHP. I have used ftp_connect() fine and works great. As soon as I try to use ftp_ssl_connect(), I get this error:

Fatal error: Call to undefined function ftp_ssl_connect()

I do have openssl extension turned on in PHP extentions. I am not sure what else there is to do as searching google there is nothing that I can find to do to make this function call work. Does anyone know when what I am missing or to check to see if something else needs to be installed on my wampserver?

Here is my php code I am using:

$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"; 
}

It obviously doesn't get past the first line because of saying that ftp_ssl_connect() is an undefined function.

Upvotes: 3

Views: 8359

Answers (2)

Yifan
Yifan

Reputation: 1245

PHP7.1.12 CentOS

I build php by myself.

/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

resolve:

# /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

check:

# 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

done!

Upvotes: 1

fusion3k
fusion3k

Reputation: 11689

From PHP Documentation:

Note: Why this function may not exist ftp_ssl_connect() is only available if both the ftp module and the OpenSSL support is built statically into php, this means that on Windows this function will be undefined in the official PHP builds. To make this function available on Windows you must compile your own PHP binaries.

Note: ftp_ssl_connect() is not intended for use with sFTP. To use sFTP with PHP, please see ssh2_sftp().

(BTW: I don't use Windows but I can't access to ftp_ssl_connect())

Upvotes: 7

Related Questions