0
votes

I need to extract data from a .gz file which is located on an ftp server. The FTP server works with IP white listing, so I submitted my local IP and my website IP (i used gethostbynameto get the IP) which were both approved.

Locally, I can run this code to reach the file:

$url="ftp://username:password@host/targetfile.gz";
$xml = simplexml_load_file("compress.zlib://$url") or die ("Cannot load file");

This runs perfectly fine and it allows me to extract data from the XML file.

When I run the script on my server however, i'm not getting a connection. I contacted the admin running the ftp server and they told me they only allow FTPS connections.

So, I proceeded with the following code to try and establish a connection:

$conn_id = ftp_ssl_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

if (!$login_result) {
    die("Cannot login.");
}

echo ftp_pwd($conn_id); // /

// close the ssl connection
ftp_close($conn_id);

This also doesn't connect. I'm new to FTP connections with PHP and FTP in general and i've got no clue on how to proceed from this point.

OpenSSL is enabled.

Can anyone point me in the right direction?

Edit: These are the error messages:

When I use the top block of code, this occurs:

Warning: simplexml_load_file(): I/O warning : failed to load external entity "compress.zlib://username:[email protected]/targetfile.gz"; in /path/to/my/website/folder/htdocs/mydomain.com/feeds/script.php on line 13

When I use the bottom block of code, I get this error:

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /path/to/my/website/folder/htdocs/mydomain.com/feeds/script.php on line 16 Cannot login.

I do not have access to the log file afaik

1
"not getting a connection" and "doesn't connect" are both pretty vague. What exact error message are you getting? + Do you have a shell access to the server? Can you connect with a standalone FTP client from the web server to FTP server? - Martin Prikryl
I do not have shell access and yes, I'm able to login to the ftp server with FileZilla. Note that I was also able to login when I ran the script through localhost / xampp server. I'm not getting any error message other than the one that comes from die("Cannot login."). Trying to describe it to the best of my abilities: I'm simply not able to login. The ftp server is not actually returning any error message so i'm in the dark about that. - Moosetuin
Do you capture PHP warnings? Do you have an access to FTP servver log file? - Martin Prikryl
When I use the top block of code, this occurs: Warning: simplexml_load_file(): I/O warning : failed to load external entity "compress.zlib://username:[email protected]/targetfile.gz" in /path/to/my/website/folder/htdocs/mydomain.com/feeds/script.php on line 13 When I use the bottom block of code, I get this error: Warning: ftp_login() expects parameter 1 to be resource, boolean given in /path/to/my/website/folder/htdocs/mydomain.com/feeds/script.php on line 16 Cannot login. I do not have access to the log file afaik. - Moosetuin
Edit this information into your question. + So I assume that ftp_ssl_connect return false, right? - Martin Prikryl

1 Answers

0
votes

I do not think there's much we can help you here.

You do not have a network connectivity between the web server and FTP server.

Note that it does not have to be because the web server has not been white-listed on the FTP server. It's also possible that the web server does not allow outgoing connections.