FTP works locally, but not remotely

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamesmcness
Forum Newbie
Posts: 4
Joined: Tue Apr 28, 2009 12:06 am

FTP works locally, but not remotely

Post 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
Last edited by Benjamin on Tue Apr 28, 2009 12:18 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: FTP works locally, but not remotely

Post by Benjamin »

ftp_connect is returning false, rather than an FTP stream. Have you reviewed the docs?

http://us3.php.net/ftp_connect
jamesmcness
Forum Newbie
Posts: 4
Joined: Tue Apr 28, 2009 12:06 am

Re: FTP works locally, but not remotely

Post 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??
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: FTP works locally, but not remotely

Post 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.
jamesmcness
Forum Newbie
Posts: 4
Joined: Tue Apr 28, 2009 12:06 am

Re: FTP works locally, but not remotely

Post 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.
jamesmcness
Forum Newbie
Posts: 4
Joined: Tue Apr 28, 2009 12:06 am

Re: FTP works locally, but not remotely

Post 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?
Post Reply