Hi all,
I am trying to connect to our FTP server with the following script.
I already have access via our FTP client (WSFTPpro) which works fine.
When I use the PHP script (see below) I get the following error:
Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/mydomain/httpdocs/fidsdata/ftptest2.php on line 9
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /var/www/vhosts/mydomain/httpdocs/fidsdata/ftptest2.php on line 16
Ftp connection has failed!Attempted to connect to [url]ftp://myserver.com/[/url] for user myuser.
$ftp_user_name = 'myuser';
$ftp_user_pass = 'mypassword';
// set up basic connection
$ftp_server = 'ftp://mydomain.com/';
$ftp_port = '21';
$conn_id = ftp_connect($ftp_server,$ftp_port);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "Ftp upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
Can anyone see where I am oing wrong.