我想用PHP连接到ftps服务器。我正在使用ftp_connect()
在我的服务器URL ftp_connect('example.google.com:7080')
中
但当我尝试连接时,会收到以下警告:
警告:ftp_connect():php_network_getaddresses:getaddrinfo失败:没有已知的此类主机
<?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);
?>
现在我得到这个错误
警告:ftp_login():登录不正确。在C:''examplep''htdocs''serve''remotedirect.php的第12行FTP连接失败!
Port应该是第二个参数。检查文档:
https://www.php.net/manual/en/function.ftp-connect.php
https://www.php.net/manual/en/function.ftp-login.php
同样对于FTPS,您应该使用其他功能:
https://www.php.net/manual/en/function.ftp-ssl-connect.php