【问题标题】:How do I connect to ftps server with port number through php?如何通过 php 连接到带有端口号的 ftps 服务器?
【发布时间】:2015-12-14 06:19:08
【问题描述】:

我想用 PHP 连接到一个 ftps 服务器。我正在使用ftp_connect()

在我的 ServerURL ftp_connect('example.google.com:7080')

但是当我尝试连接时收到此警告:

警告: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);


?>

现在我得到了这个错误

警告:ftp_login():登录不正确。在第 12 行的 C:\xampp\htdocs\serve\remotedirect.php FTP 连接失败!

【问题讨论】:

  • Login incorrect 应该很明显。
  • 我投票结束这个问题作为题外话,因为 OP 使用 StackOverflow 作为实时调试工具,例如一旦原始问题得到解决,就向问题添加问题。这会使答案变得混乱。

标签: php ftps


【解决方案1】:

【讨论】:

  • 您能否修复该错误,因为我无法打开我的服务器文件夹和文件现在我发送代码请破解该代码
  • 你应该在你的答案中添加一个代码示例来改进它。仅链接的答案在 SO 上非常受欢迎,即使它们来自可靠的来源。他们总有一天会死去,答案变得毫无用处。
  • @GeraldSchneider 我认为,如果官方文档死了,那么不仅答案变得毫无用处,而且也是一个问题。
  • @GBoomanikandan 你的代码现在很好,我刚刚运行它,它工作正常。仔细检查您的登录名、密码、服务器地址和端口号。除此之外,您粘贴的代码适用于普通 FTP(不安全)连接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-14
  • 2016-07-18
  • 2011-03-14
  • 1970-01-01
  • 2021-05-24
相关资源
最近更新 更多