FTP in PHP on networksolutions.com

I am very frustrated with a problem involving FTP and PHP:

Here is the condensed version of my problem: I created a website for a client using PHP on go daddy.com. The code uses FTP within PHP. Works great on their. I moved the site over to Network Solutions and the FTP portion of the code stopped working.

To remove complexity of the problem, I wiped my code out on the NS site and created a single php file that tries to connect to an FTP site, get a dir listing, and log out. I thought I could start simple and work my way up until I could find the problem. You can see the code below.

When I run this script on NS it just times out like it either couldn’t resolve the name or get a connection to the Internet. If I replace the host address (ftp.microsoft.com with anything else it makes no difference, ftp.funet.fi, ftp.networksolutions.com, nothing). It just chews on that script until it times out.

Same coded tested on three different hosting sites (go daddy, a plus, etc…) works great. It instantly comes back.

I replaced the domain name with the IP address and it makes no difference. It is like it can’t even get to the Internet so it just times out.

I called NS and I get this “We don’t troubleshoot scripts” crap but I am at a loss given the simplicity of this script and the error. They suggestion either the code bad or the php.ini file is bad. I use the same code across three test sites and it works. I review NS’s temp php file and it seems fine. However, I make a copy of the other php.ini files from the other sites and try each one individually to see it makes a difference. Nothing, just times out.

I was wondering if anyone here had any suggestions.

Thanks for reading!
-P

[php]<?php
$host = ‘ftp.funet.fi’;
$usr = ‘ftp’;
$pwd = ‘[email protected]’;

$conn_id = ftp_connect($host, 21) or die (“Cannot connect to host”);

ftp_login($conn_id, $usr, $pwd) or die(“Cannot login”);
$buff = ftp_rawlist($conn_id, ‘/’);
ftp_close($conn_id);
var_dump($buff);
?>[/php]

On NetSol’s site, I found a sample of their connection setup for FTP.
It was identical except one item. It seems that some hosting companies (most now) are using “virtual” hosting.
Which basically means that many sites are hosted on one server and routed as needed.

Anyways, it appears you do not need the port number in your connection request.
So, your --> ftp_connect($host, 21) <–
becomes --> ftp_connect($host) <–

Try that and let us know if it works… (I did not attempt this as I have FTP shut off right now…)

ErnieAlex,

First, thank you for your help and reply. I very much appreciate your time!

Second, I made the change as you had suggested but it did not appear to make any difference. It just waits and waits and then I get a timeout. I swear it looks like it is trying to get out but it just sits there. I have tried both a domain name and an IP address but it does not make a difference.

I am now past 24 hours waiting for NS to get back with me.

Any other suggestion? :slight_smile:

Hey! I was sending the message below when I got thinking and looked at your code again.
It seems that if you use the ftp_rawlist command, you have to supply a directory. You used
“/” as the folder… Try “.” instead. See if that works… This is the code I found as a sample to
do what you were trying… (after is the message I was sending…)
[php]

<?php $conn = ftp_connect("ftp.testftp.com") or die("Could not connect"); ftp_login($conn,"USERID","PASS"); print_r (ftp_rawlist($conn,".")); ftp_close($conn); ?>

[/php]

Searching around for you, I found a large number of people having the same problems.
Some of them just start working later on. Some of them were having troubles due to the actual
FTP address that is used. It is something like D03251.netsolhost.com or whatever…
So, something like “ftp.networksolutions.com” will not work as it does not point at your FTP server.
If you are trying to download from another server, it depends on your connection. (UserID/Pass)

So, all this brings us up to another question. Have you connect to the location you are trying with
a FTP-Client? Like CuteFTP or one of those? Can you connect directly that way? If so, then, I would
have to look at the ftp_rawlist functions and see if that is your issue.

Hi ErnieAlex,

Again, thank you so much for the help.

I read through your 2nd reply and I made the change and it did not make a difference (though, thanks for the suggestions).

I would like to point that no matter what I enter, the PHP code never gets past this:

$conn = ftp_connect(“ftp.microsoft.com”) or die(“Could not connect”);

I can replace ftp.microsoft.com with any ftp site, ftp IP address, or a variable and it hits that line and chews on it until it times out. It ‘feels’ like the server can’t find the site, dns server, or maybe a connection to the Internet.

I know you can’t see the code but if you want to see what I see go here (my test page):

http://www.pawprintsid.com/start6.php

ErnieAlex, can you think of anything in the php.ini file that would cause this?

Here is the current code on that page:

[php]<?php
$host = ‘ftp.microsoft.com’;
$usr = ‘ftp’;
$pwd = ‘[email protected]’;

// connect to FTP server (port 21)
$conn_id = ftp_connect(“ftp.microsoft.com”) or die (“Cannot connect to host”);

// send access parameters
ftp_login($conn_id, $usr, $pwd) or die(“Cannot login”);
$buff = ftp_rawlist($conn_id, ‘/’);
ftp_close($conn_id);
var_dump($buff);
?>[/php]

Thank you again!!

ErnieAlex,

I have an update:

If I change:

$conn_id = ftp_connect(“ftp.microsoft.com”) or die (“Cannot connect to host”);

to

$conn_id = ftp_connect(“ftp.microsoftzzz.com”) or die (“Cannot connect to host”);

I get this error:

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /data/25/2/40/20/2692835/user/2957560/htdocs/start6.php on line 8

So, I think it shows that it does get to the Internet and it must ‘see’ the site.

If I put the address back correctly it still just sits there and then gives me a Cannot connect to host after a min or so.

I then put this:

[php]<?php
$host = ‘ftp.microsoft.com’;
$usr = ‘ftp’;
$pwd = ‘[email protected]’;

// connect to FTP server (port 21)
$conn_id = ftp_connect(“ftp.microsoft.com”) or die (“Cannot connect to host”);

ftp_login($conn_id, $usr, $pwd) or die(“Cannot login”);
ftp_close($conn_id);
?>[/php]

Made no difference.

Could there be a firewall issue with them?

Running out of ideas. But, here is one to try…

Place this in your PHP code before anything else. It should display ALL errors including connection errors.

error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

If that shows the error, let us know. If not, we will have to use the “TRY-CATCH” method to try to capture the actual error that your connection is throwing. Good luck…

If you’re using their shared hosting, then no amount of help we provide will help you. They don’t allow it. You’ll have to spend in upwards of $500 a year for either a dedicated server or a virtual private server. That’s one reason the company i work for canned godaddy, because we needed to do server-to-server transfers.

The error you describe Name or Service not recognized is from code trying to resolve ftp to a port number, usually on linux this is found in /etc/services and you can add different named services to a port number and type of packet system. If netsol cannot resolve the issue you may end up looking for a socket ftp script.
Such as this class: http://www.phpclasses.org/package/1743-PHP-FTP-client-in-pure-PHP.html

Definately a netsol issue tho

Pentad, It can not be done your way… I found out from NetSol, they block FTP’s. They allow it to be done thru external FTP clients only. Therefore, if you have a program like that, you could make calls to it. But, this would have to be done client-side and therefore could not be done for someone else, just you. Not for a general user. My suggestion is to have your client move to GoDaddy or another host that allows FTP. You can user port 443 if your FTP is for users to connect to your site only. Regular FTP clients will not be able to connect normally.

Here is the comment from NetSol…


Our hosting firewall blocks all outgoing connections other than on port 80 or 443. You can do FTP to the server itself by using “localhost” as the FTP server (this technique is used by many Open Source applicaitions like WordPress and Joomla to be able to do updates). The best way to get data from an external server on nsHosting Shared Unix is to use curl and connect on port 80 or 443.

If you must have the external FTP connection, nsHosting VPS is the only thing we offer that would allow the external connection on port 21 (FTP) or 22 (sFTP).

That’s all I can find for you… Hope you figure out a work around…

I want to sincerely thank everyone who help me with this post. I very much appreciate your time in helping with this problem.

Having read all the posts and especially ErnieAlex’s last one, I abandoned my FTP code and am just doing some file copying and rearranging of resources.

I wish NS was a bit more helpful with their tech support.

Anyway, this thread was invaluable to not only check my code but assure me that I am not going crazy. :slight_smile:

May I say all of you “ROCK!”

I still love PHP as much as ever.

I hope all of you have a great week and weekend!

Cheers!
-P

Sponsor our Newsletter | Privacy Policy | Terms of Service