PHP ftp_put 警告 警告:ftp_put() [function.ftp-put]:类型设置为 I.in
当我尝试使用 PHP 的 ftp_put 函数上传文件时,早些时候出现错误:
警告:ftp_put() [function.ftp-put]: 无数据连接
现在,我尝试打开被动模式:
< code>ftp_pasv($conn_id, true);
然后出现错误:
Warning: ftp_put() [function.ftp-put]: Type set to I. in
ftp_login 已正确完成,并且它说成功了。
现在它给出了新的警告:警告:ftp_put()[function.ftp-put]:abc.txt:无法打开或删除包含正在运行的程序的文件。
任何想法,为什么文件不传输?
谢谢 !
这是我的代码片段:
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("You do not have access to this ftp server!");
if ((!$conn_id) || (!$login_result)) {
// wont ever hit this, b/c of the die call on ftp_login
echo "<span style='color:#FF0000'><h2>FTP connection has failed! <br />";
echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>";
exit;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name <br />";
}
//turn passive mode on
ftp_pasv($conn_id, true);
$upload = ftp_put($conn_id, $destination_file.$name, $filename, FTP_BINARY);
if (!$upload) {
echo "<span style='color:#FF0000'><h2>FTP upload of $filename has failed!</h2></span> <br />";
} else {
echo 'Uploaded';
}
ftp_close($conn_id);
When i try to upload files using PHP's ftp_put function, earlier it was erroring:
Warning: ftp_put() [function.ftp-put]: No data connection
Now, i tried to put passive mode on:
ftp_pasv($conn_id, true);
then comes error:
Warning: ftp_put() [function.ftp-put]: Type set to I. in
ftp_login is done properly and it says Successfully.
Now it gives new warning: Warning: ftp_put() [function.ftp-put]: abc.txt: Cannot open or remove a file containing a running program.
Any ideas, why file not tranferring ?
Thanks !
Here is my code snippet:
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("You do not have access to this ftp server!");
if ((!$conn_id) || (!$login_result)) {
// wont ever hit this, b/c of the die call on ftp_login
echo "<span style='color:#FF0000'><h2>FTP connection has failed! <br />";
echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>";
exit;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name <br />";
}
//turn passive mode on
ftp_pasv($conn_id, true);
$upload = ftp_put($conn_id, $destination_file.$name, $filename, FTP_BINARY);
if (!$upload) {
echo "<span style='color:#FF0000'><h2>FTP upload of $filename has failed!</h2></span> <br />";
} else {
echo 'Uploaded';
}
ftp_close($conn_id);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
http://php.net/ftp_pasv
我收到了相同的(不是很有描述性)错误消息
E_WARNING ftp_get(): Type set到我。
。我发现这是因为运行PHP的服务器没有可见的公共IP(它是我工作站上的虚拟服务器)。
解决方案是使用被动模式。默认设置(主动模式)在实时服务器上没有问题,因为实时服务器具有可见的公共IP。
http://php.net/ftp_pasv
I was recieving same (not very descriptive) error message
E_WARNING ftp_get(): Type set to I.
.I found out that it is because server running PHP did not have visible public IP (it is virtual server on my workstation).
Solution was using passive mode. Default setting (active mode) did not have problem on live server, because live server has visible public IP.
当 FTP 守护程序卡在打开的上传文件并等待您写入时,您看到的最后一个错误就会发生。
每当您通过 FTP 服务器成功打开连接时,请准备在进程完成或由于任何错误而终止时使用以下函数关闭连接。
您的脚本可能将其连接保持打开状态,并且 FTP 服务器对此感到困惑。尝试在适当的地方添加ftp_close,看看脚本运行是否更流畅。
The last error you are seeing happens when the FTP daemon is stuck with the uploaded file open and waiting for you to write to it.
Anytime you successfully open a connection over an FTP server, be prepared to close the connection with the following function when the process completes or terminates due to any errors.
It's possible your script is leaving its connections open and the FTP server is getting confused by this. Try adding ftp_close in the appropriate places and see if the script runs more smoothly.
我尝试过在 PHP 中使用 ftp 函数,发现使用
file_put_contents()
更容易,如下所示:您仍然可以检查它是否成功,当然也可以检查所有这些好东西。
I've tried using the ftp functions in PHP and found it was much easier to use
file_put_contents()
like the following:You can still check if it was successful and all that good stuff of course too.
您的 ftp 设置看起来没问题,尝试将文件名 $destination_file.$name 放入单个变量中,转储该变量并确保该文件以绝对路径存在(如果它与脚本不在同一文件夹中)。这是我快速浏览时看到的唯一细节,可能会阻碍您的上传。
确保您的文件没有在编辑器中打开!如果文件是 .txt,您可以使用 FTP_ASCII,尽管二进制文件不会造成问题。
祝你好运!
Your ftp setup looks ok, try putting the filename $destination_file.$name in a single variable, dump the variable and make sure this file exists with absolute path if it is not in the same folder as your script. That is the only detail I saw in a quick glance, that could choke your upload.
Make sure your file is not opened in an editor! And if the file is .txt you can use FTP_ASCII although being in binary should not cause a problem.
Good-luck!
我找到了如下解决方案:
我刚刚与 EUKHOST 服务器支持人员进行了交谈,
要点是支持人员现在在服务器上为 FTP 打开了一个
被动端口
范围,他告诉我们尝试 FTP 上传现在。如果您可以尝试使用一些测试文件并且成功完成..I found its solution as below:
I just talked to EUKHOST server support
Main point in this was that the support person now opened a
passive port
range for FTP on server, and he told us to try the FTP upload now. If you could try it with some testfile and it went through successfully..末尾添加以下行
在打开的 /etc/vsftpd.conf 并添加
pasv_promisculous=YES___ 最后。
Add following lines at the end of
open /etc/vsftpd.conf and add
pasv_promiscuous=YES___ at the end.
就我而言,触发此错误的问题是我尝试上传的文件对于接收服务器的配置来说太大。
In my case, the issue triggering this error was that the file I was trying to upload was too large for the recieving server's configuration.