Reputation: 124
I want to connect to an ftps server with PHP. I am using ftp_connect()
In my ServerURL ftp_connect('example.google.com:7080')
But I get this warning when I try to connect:
Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known
<?php
$ftp_server="example.google.com";
$ftp_port="7080";
$ftp_serusername="example";
$ftp_serpass="Pass@123";
// set up basic connection
$conn_id = ftp_connect($ftp_server,$ftp_port) or die("Couldn't connect to $ftp_server");
// login with username and password
//if($conn_id){
$login_result = ftp_login($conn_id, $ftp_serusername, $ftp_serpass);
//}
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
}
// 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";
// }
// Retrieve directory listing
$files = ftp_nlist($conn_id, '/remote_dir');
// close the FTP stream
ftp_close($conn_id);
?>
now i got this error
Warning: ftp_login(): Login incorrect. in C:\xampp\htdocs\serve\remotedirect.php on line 12 FTP connection has failed!
Upvotes: 2
Views: 7798
Reputation: 652
Port should be second parameter. Check documentation:
https://www.php.net/manual/en/function.ftp-connect.php
https://www.php.net/manual/en/function.ftp-login.php
Also for FTPS you should use other function:
https://www.php.net/manual/en/function.ftp-ssl-connect.php
Upvotes: 3