PHP ftp_put 警告警告:ftp_put() [function.ftp-put]: Type set to I. in

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6147806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:29:08  来源:igfitidea点击:

PHP ftp_put warning Warning: ftp_put() [function.ftp-put]: Type set to I. in

phpfileftptransfer

提问by Aditya P Bhatt

When i try to upload files using PHP's ftp_put function, earlier it was erroring:

当我尝试使用 PHP 的 ftp_put 函数上传文件时,之前出现错误:

Warning: ftp_put() [function.ftp-put]: No data connection

Warning: ftp_put() [function.ftp-put]: No data connection

Now, i tried to put passive mode on:

现在,我尝试开启被动模式:

ftp_pasv($conn_id, true);

ftp_pasv($conn_id, true);

then comes error:

然后是错误:

Warning: ftp_put() [function.ftp-put]: Type set to I. in

Warning: ftp_put() [function.ftp-put]: Type set to I. in

ftp_login is done properly and it says Successfully.

ftp_login 已正确完成并显示成功。

Now it gives new warning: Warning: ftp_put() [function.ftp-put]: abc.txt: Cannot open or remove a file containing a running program.

现在它给出了新的警告:警告: 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);

采纳答案by Tanoro

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.

您看到的最后一个错误发生在 FTP 守护进程卡住上传的文件并等待您写入文件时。

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.

每当您通过 FTP 服务器成功打开连接时,请准备好在该过程完成或因任何错误而终止时使用以下函数关闭连接。

ftp_close($conn_id);

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.

您的脚本可能会保持其连接处于打开状态,而 FTP 服务器对此感到困惑。尝试在适当的地方添加 ftp_close ,看看脚本是否运行更流畅。

回答by Martin

http://php.net/ftp_pasv

http://php.net/ftp_pasv

$resource = ftp_connect('ftp.example.com');
ftp_login($resource, 'username', 'password');

# set this to true
ftp_pasv($resource, true);

ftp_get(...);
ftp_put(...);

I was recieving same (not very descriptive) error message E_WARNING ftp_get(): Type set to I..

我收到了相同的(不是很详细的)错误消息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).

我发现这是因为运行 PHP 的服务器没有可见的公共 IP(它是我工作站上的虚拟服务器)。

Solution was using passive mode. Default setting (active mode) did not have problem on live server, because live server has visible public IP.

解决方案是使用被动模式。默认设置(主动模式)在实时服务器上没有问题,因为实时服务器具有可见的公共 IP。

回答by dtbarne

I've tried using the ftp functions in PHP and found it was much easier to use file_put_contents()like the following:

我试过在 PHP 中使用 ftp 函数,发现它更容易使用file_put_contents(),如下所示:

$remote_file = "ftp://username:[email protected]/path/to/file.txt";
file_put_contents($remote_file, $file_contents);

You can still check if it was successful and all that good stuff of course too.

您仍然可以检查它是否成功,当然还有所有好东西。

回答by Aditya P Bhatt

I found its solution as below:

我找到了它的解决方案如下:

I just talked to EUKHOST server support

我刚刚与 EUKHOST 服务器支持人员进行了交谈

Main point in this was that the support person now opened a passive portrange 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..

主要的一点是,支持人员现在passive port在服务器上为 FTP打开了一个范围,他告诉我们现在尝试 FTP 上传。如果你可以用一些测试文件尝试它并且它成功通过了..

回答by stefgosselin

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.

您的 ftp 设置看起来没问题,尝试将文件名 $destination_file.$name 放在单个变量中,转储该变量并确保该文件存在于绝对路径中,如果它与您的脚本不在同一文件夹中。这是我快速浏览的唯一细节,可能会阻止您的上传。

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.

确保您的文件没有在编辑器中打开!如果文件是 .txt,您可以使用 FTP_ASCII 虽然二进制文件应该不会引起问题。

Good-luck!

祝你好运!

回答by rajkamal

Add following lines at the end of

在末尾添加以下几行

open /etc/vsftpd.confand add pasv_promiscuous=YES___ at the end.

打开/etc/vsftpd.conf并在最后添加 pasv_promiscuous=YES___。