我使用简单的PHP脚本将文件上传到ftp服务器时遇到了奇怪的行为。
我创建了以下我的代码的精简版本,它产生了同样的错误:
<?php
error_reporting(E_ALL);
echo phpversion();
$ftpUrl = "mydomain";
$ftpUserName = "myuser";
$ftpPassword = 'mypass';
$fileContents = "test";
file_put_contents('text.txt', $fileContents);
//open ftp connection
$conn_id = ftp_connect($ftpUrl, 1030);
if(!$conn_id)
die('error while connecting to ftp');
$login_result = ftp_login($conn_id, $ftpUserName, $ftpPassword);
if (!$login_result)
die('ftp login failed!');
//switch to passive mode
ftp_pasv($conn_id, true);
//upload file to ftp
try
{
$fileToUpload = fopen('text.txt', 'r');
if($fileToUpload == false)
die('can\'t open file to send!');
$upload = ftp_fput($conn_id, 'testfile.txt', $fileToUpload, FTP_ASCII);
}
catch(Exception $e)
{
fclose($fileToUpload);
ftp_close($conn_id);
die('Error while uploading to ftp');
}
fclose($fileToUpload);
ftp_close($conn_id);
if (!$upload)
die('ftp upload failed');
&GT;
在客户端的ftp服务器上运行脚本时出现以下错误。 (尝试上传文件时出错,设置连接登录工作)
Warning: ftp_fput() [function.ftp-fput]: php_connect_nonb() failed: Operation now in progress (115) in {path} on line 38
Warning: ftp_fput() [function.ftp-fput]: Type set to A in {path} on line 38
ftp upload failed
服务器使用php版本5.3.28
我几个小时以来一直在努力解决这个错误,这让我发疯了。有线索吗?
答案 0 :(得分:-1)
Ftp_put()将文件 name 作为参数,您传递文件 handle
尝试
ftp_put($conn_id,'testfile.txt', 'test.txt', FTP_ASCII);