【发布时间】:2021-03-07 22:24:11
【问题描述】:
我能够正常连接到 filezilla (ftp)。但是ftp_fput () 方法的返回返回 false。这意味着您无法上传文件。
这是我的代码:
$server = "host.host.ws";
$user = "username";
$pass = "password";
// call function
$conn = uploadFTP($server, $user, $pass, $local_file, $remote_file);
function uploadFTP($server, $username, $password, $local_file, $remote_file) {
$connection = ftp_connect($server);
if (@ftp_login($connection, $username, $password)){
ftp_pasv($connection, true) or die("Unable switch to passive mode");
$fp = fopen('php://temp', 'r+');
fwrite($fp, 'content within the file');
rewind($fp);
// the file is not generated in the remote directory: /App/data/Json/File.json
if (ftp_fput($connection, '/App/data/Json/File.json', $fp, FTP_ASCII))
echo 'generated file!';
fclose($fp);
ftp_close($connection);
return true;
} else {
return false;
}
该文件只会在显示消息时生成:“已生成文件!”,但事实并非如此。
代码没有显示任何明确的错误,我的问题是,为什么这段代码没有在目录中生成文件?你能分享一下这个问题的解决方案吗?
【问题讨论】:
-
向我们显示来自任何命令行/GUI FTP 客户端的日志文件,以便成功上传相同的文件。 + 向我们展示您如何检查“这不是正在发生的事情”。