Question Regarding FTP Functions in PHP

software development

#1

The code I’m writing is not going to be staying on my account, but while I’m at home, I do not have access to the server it will be on, hence why I’m using my dreamhost space to test this stuff.

Anyway, I’m working on a small application that will be using PHP’s FTP functions.

My code, which is pretty standard “i’m just trying the basic stuff to see if I can get it to work” code was taken almost directly from the PHP.net site.

But the problem is, when I upload it to my space and load the page in the browser, I get the following error messages:
[b]
Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/.iota/julisana/julisana.com/union_station_application/ftp_test.php on line 21

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/.iota/julisana/julisana.com/union_station_application/ftp_test.php on line 22

Warning: ftp_close() expects parameter 1 to be resource, boolean given in /home/.iota/julisana/julisana.com/union_station_application/ftp_test.php on line 41
[/b]
I’m not sure exactly what’s going wrong in the code, and searching through this board’s archives hasn’t really lead to anything specific as far as fixing the problem, as any posts with any “suggestions” are a few years old, and a few PHP Versions ago.

Thanks!
–Lisa

P.S. The code I’m using:
[i]
$ftp_server = gethostbyname(“ftp://IP Address”);
$ftp_user_name = “Username”;
$ftp_password = “Password”;

$connection_id = ftp_connect($ftp_server);
$login_result = ftp_login($connection_id,$ftp_user_name,$ftp_password);

if ((!$connection_id) || (!$login_result))
{
echo “

FTP Connection has Failed.

\n”;
echo "

Attempted to connect to ";
echo $ftp_server;
echo " for user ";
echo $ftp_user_name;
echo “.

\n”;
} //end if
else
{
echo "

Connection to ";
echo $ftp_server;
echo " for user ";
echo $ftp_user_name;
echo “was successful.

\n”;
}
ftp_close($connection_id);
[/i]

#2

ftp_connect takes a host name or IP address as its first parameter. You don’t need to use gethostbyname and the ftp:// bit isn’t required.

[code]$ftp_server = “a.b.c.d”;
// or: ftp_server = “hostname”;
$ftp_user_name = “Username”;
$ftp_password = “Password”;

$connection_id = ftp_connect($ftp_server);
[/code]


#3

I think you’re my new favorite person.

Thank you so much!!