gpt4 book ai didi

PHP ftp_put 失败并返回 "Warning: ftp_put (): PORT command successful"

转载 作者:可可西里 更新时间:2023-11-01 12:45:24 25 4
gpt4 key购买 nike

文件在 FTP 服务器上创建,但其大小始终为 0 字节。请给我一个解决方案,以便文件上传成功。

我不断收到此警告:

Warning: ftp_put (): PORT command successful in C: \ xampp \ htdocs \ mailing \ teskirim-file-simpan2.php on line 30
FTP upload has failed!

enter image description here

我的脚本是:

<?php
$ftp_server = "********";
$ftp_serverpath = "ftp.".$ftp_server;
$ftp_user_name = "********";
$ftp_user_pass = "***********";
$email_dir = "*******@*********";

$nyambungkeftp = ftp_connect($ftp_server);
if (false === $nyambungkeftp) {
throw new Exception('Unable to connect');
}

$loggedInnyambungkeftp =
ftp_login($nyambungkeftp, $ftp_user_name, $ftp_user_pass);
if (true === $loggedInnyambungkeftp) {
echo 'Success!';
} else {
throw new Exception('Unable to log in');
}

if ((!$nyambungkeftp) || (!$loggedInnyambungkeftp)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$dest = 'detectip.txt';
$source = 'C:\xampp\htdocs\persuratan\file2\detectip.txt';

echo $dest;
echo $source;
$upload = ftp_put($nyambungkeftp, $dest, $source, FTP_ASCII);


// 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($nyambungkeftp);

?>

最佳答案

PHP 默认为主动 FTP 模式。由于无处不在的防火墙/NAT/代理,如今主动模式几乎无法工作。

你几乎总是需要使用被动模式。

为此调用 ftp_pasv ftp_login 之后:

ftp_pasv($nyambungkeftp, true);

请参阅关于 FTP connection modes文章,了解为什么您通常需要使用被动模式。

关于PHP ftp_put 失败并返回 "Warning: ftp_put (): PORT command successful",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39945860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com