Page 1 of 1

FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 12:17 am
by jamesmcness
Hi
I'm trying to make a script that will transfer files to a remote server via ftp. It seems to work when targetting the server the script is on, but I can't for the life of me create a connection to any other ftp server (it fails to even create the stream, so it's not a username/password issue).
Here's my code:

Code: Select all

<?php 
$port= $_GET['port'];
$host = $_GET['host'];
$username=$_GET['user'];
$password=$_GET['pass'];
// do ftp stuff
$connection = ftp_connect($host,$port); 
$login = ftp_login($connection, $username, $password); 
if (!$connection || !$login) { 
    die('Connection attempt failed!'); 
} else{
    echo 'Connection success';
}
 
ftp_close($connection);
?>

The error message I get is: Warning: ftp_login() expects parameter 1 to be resource, boolean given

I'm very new to php so I'm at a loss, hoping someone can shed some light!!

thanks,
JMC

Re: FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 12:21 am
by Benjamin
ftp_connect is returning false, rather than an FTP stream. Have you reviewed the docs?

http://us3.php.net/ftp_connect

Re: FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 12:45 am
by jamesmcness
Thanks astions, I have read the docs/googled.
I realise that the connection is failing and returning false, but the real question is why every other ftp server I try failing??

Re: FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 12:55 am
by Benjamin
There are a lot of things that can cause a network connection to fail.. It may be a firewall issue if you are on a shared host.

Re: FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 12:59 am
by jamesmcness
Yeah, the php script is hosted on a shared host, could that effect thigns?
Not sure if it's relevant but I can successfully connect to the remote ftp servers via my windows command line prompt.

Re: FTP works locally, but not remotely

Posted: Tue Apr 28, 2009 3:54 am
by jamesmcness
So how is it possible to open an ftp connection via php to a remote domain that is hosted on a shared server?