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

7

9

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);
Ultramundane answered 27/5, 2011 at 4:19 Comment(7)
can you please post your code?Miguelmiguela
Are you specifying the stream as the first argument?Ariose
added now.. pl guide me furtherUltramundane
Where is the FTP server located? I saw this problem in some buggy FTP server where the file handle is not closed and it thinks that it's still copying data, especially if we forget to specify ftp_closeBurgonet
ftp_close is there on the code.. let me put here as well :)Ultramundane
Yep yep not saying that your code doesn't contain ftp_close, but happened to me. If you have access to the FTP server and can restart the service maybe you can try that.Burgonet
well, that doesn't work for me as well, strange but solution i found is that, i connect to live chat and ask them to check, when i do the same 2-3 times and then try, ftp transfer works.. weird but it works for me now..Ultramundane
K
3

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.

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.

Ko answered 27/5, 2011 at 4:53 Comment(0)
T
20

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..

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.

Turbit answered 15/6, 2015 at 12:53 Comment(2)
Note that the ftp_pasv call must be done after the login or it will not work.Dismissal
Keep in mind to do this in the correct order : ftp_login then ftp_pasvGodfry
K
3

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.

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.

Ko answered 27/5, 2011 at 4:53 Comment(0)
L
3

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

$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.

Lakitalaks answered 27/5, 2011 at 4:55 Comment(0)
M
0

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!

Mimamsa answered 27/5, 2011 at 4:53 Comment(0)
U
0

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..

Ultramundane answered 8/7, 2011 at 19:29 Comment(0)
Z
0

Add following lines at the end of

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

Zaragoza answered 15/10, 2015 at 11:10 Comment(0)
M
0

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.

Maupassant answered 18/1, 2023 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.