Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1927
  • Last Modified:

PHP5 FTP issue

hy
here is my problem
our administrator just upgraded our webserver to PHP5
I had a script that i used to upload files
now i get the following message

Warning: ftp_put() [function.ftp-put]: TYPE is now 8-bit binary in /../../../addfile.php on line 83

            $upload=ftp_put($connect,$dest,$source,FTP_BINARY);

tks
0
rsandor
Asked:
rsandor
  • 5
  • 4
  • 2
  • +3
1 Solution
 
Eric AKA NetminderCommented:
Can you post the code that's giving you the problem? It looks like there's a parameter associated with a file type that's been changed/added and it is missing from your instructions...
0
 
rsandorAuthor Commented:
//check if there is work to do
   if (($HTTP_POST_FILES['FISUP']['name']=='')||($_POST['descriere']==''))
   {
     $msg="Nu s-a efectuat nici o operatie!!";
   }
   else
   {
//establishing ftp connection
      $connect=ftp_connect($ftp_server);
      $login=ftp_login($connect, $ftp_user, $ftp_password);
      ftp_pasv($connect,true);
      if ((!$connect) || (!$login))
       {
        $msg="Eroare FTP!!";
     }
    else
      {

//opening database

          $db=deschide();
            $interogare="SELECT * FROM nomenclator WHERE id=".$_POST['idp'];
            $rez=mysql_query($interogare);
            $rand=mysql_fetch_array($rez,MYSQL_ASSOC);

//verifying path and building if necessary

            if (!is_dir(strtolower($rand[producator])))
             {
               $dir1=ftp_mkdir($connect,strtolower($rand[producator]));
               if (!$dir1) $msg.="Directorul ".strtolower($rand[producator])." nu a putut fi creat!<br>";
             }
            if (is_dir(strtolower($rand[producator])))
             {
               chdir(strtolower($rand[producator]));
               if (!is_dir(strtolower($rand[cod])))
                {
                    $dir2=ftp_mkdir($connect,strtolower($rand[producator])."/".strtolower($rand[cod]));
                    if (!$dir2) $msg.="Directorul ".strtolower($rand[cod])." nu a putut fi creat!<br>";
                }
             }
            if (ftp_alloc($connect, filesize($HTTP_POST_FILES['FISUP']['tmp_name']), $result))
//i did not use ftp_alloc before, still the same warning
//moving file to right location
$upload=ftp_put($connect,strtolower($rand[producator])."/".strtolower($rand[cod])."/".$HTTP_POST_FILES['FISUP']['name'],$HTTP_POST_FILES['FISUP']['tmp_name'],FTP_BINARY);
            else
            {
              echo "Unable to allocate space on server.  Server said: $result\n";
            }
            
            if (!$upload)
              {
                $msg="Eroare la transfer FTP!";
              }
            else
             {
             }
            inchide($db);
            ftp_close($connect);
    }

so here is all the code
it does the following :
builds the target path from a database (this works)
after building the path (if necessary) it moves the uploaded file to it's right location
at least it did before

0
 
Eric AKA NetminderCommented:
Okay, I'll be honest about it -- I'm very much a novice at PHP -- but I'm going to assume you've gone through http://us2.php.net/ftp and the related pages there. But unless someone comes along to deal with your issue, I think I'd do what I did when I first started learning ASP, and javascript, and everything else: I'd go back to basics. In other words, take out the path building, and see if your FTP upload code works. If that works, then you know the problem is with the path building; if it doesn't then you can simplify it even further.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rsandorAuthor Commented:
did that, same result, and as i sayd, the script worked before the upgrade
it must be a php5 issue
0
 
Eric AKA NetminderCommented:
Agreed, and it must be in the code, which is posted at the link above.

There IS one other possibility, but I'm not familiiar enough with PHP servers and error messages to be absolutely certain. In IIS, the FTP server is NOT the same as the WWW server -- they're usually the same machine, but one has to start that service and give the appropriate permissions or it won't work, even if a web site does. Is it possible that in upgrading to PHP5, the permissions didn't carry over, or that there's a different service that needs to be started?
0
 
rwestonCommented:
I see:
$upload=ftp_put($connect,strtolower($rand[producator])."/".strtolower($rand[cod])."/".$HTTP_POST_FILES['FISUP']['name'],$HTTP_POST_FILES['FISUP']['tmp_name'],FTP_BINARY);

That's a little messy; what i think you could do is clean it up a bit and do:

$dest = strtolower($rand[producator])."/".strtolower($rand[cod])."/".$HTTP_POST_FILES['FISUP']['name'];
$source = $HTTP_POST_FILES['FISUP']['tmp_name'];

$upload=ftp_put($connect, $dest ,$source,FTP_BINARY);

echo your source and destination and see if those HTTP_POST_... variables are available/defined:

Because according to: http://www.php.net/manual/en/language.variables.predefined.php
"As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive. "  Maybe your admin took it upon his/herself to disable.
0
 
rwestonCommented:
Try as well:

print_r($_FILES) and see if the Temp file is even created.  With the upgrade the old php.ini will have been replaced and maybe a temp directory was not set for File Upload?
0
 
rsandorAuthor Commented:
i've tried all that, i've done a simple script for a single file like $upload=ftp_put($connect,$dest,$source,FTP_BINARY);
also the temp file is created and register_long_arrays is enabled
i've also tryed with copy and move_uploaded_file and it works, but this is not an option for me:(
0
 
mattjp88Commented:
ok, since the script worked with a previous version of PHP, that means it is obviously due to a change in an internal function of PHP.  I suggest you either rewrite the code from the ground up, or you use one of the many premade scripts that do work with PHP 5.  If you want, you could strip a premade script down to exactly what you need, instead of all the extra features....

I would go with the rebuild the code idea, simply because since this function has changed, chances are others have as well.  Probably a simular change, so if you figure this one out, you will unlock the secrets to make other "broken" functions....
0
 
ThGCommented:
I tend not to believe that upgrading from PHP4 to PHP5 caused the real problem, given that you are passing the correct parameters to ftp_put() php function.

> $upload=ftp_put($connect,$dest,$source,FTP_BINARY);

using var_dump($connect,$dest,$source); would help before (or right after) the failing call. Socket data would be great but you need a network sniffer in order to do that. You may ask your system administrator to help you achieving this data.
0
 
rsandorAuthor Commented:
ok, i've sorted it out,
on the old server i could do ftp upload only with passive mode on,
now it works with passive mode off ??
don't know why

i know with passive mode on connections are initiated by the client, but here i don't think is the case, the upload itself is a HTTP upload, the ftp transfer is made on the server?

so, i don't know what to do now with the question?
i would give some points to ThG, var_dump was somehow usefull to me, altought did not solve the problem, the real problem was in the code ftp_pasv($connect,true);
and if there is someone to explain why this thing with passive mode i'll split the points
0
 
rsandorAuthor Commented:
ok, i just had a conversation with our admin, he says it's becouse of some firewall settings,:P
but now what shall i do with the points, none of the answers helped me with  my problem
i expect an advice from ThG, who is the page editor

be cool instantly!
0
 
Eric AKA NetminderCommented:
Neither the file type nor the physical locations of the files makes any difference; for example, if your server was located hundreds of miles from you, you might transfer a file from one folder to another, and the method for doing that -- absent something like a VPN that would allow you access to the machine -- would be to use FTP. It's also not an HTTP upload per se; it's an FTP upload performed by HTTP scripting (you can use other scripting types to accomplish the same thing).

This code:

//establishing ftp connection
     $connect=ftp_connect($ftp_server);
     $login=ftp_login($connect, $ftp_user, $ftp_password);
     ftp_pasv($connect,true);
     if ((!$connect) || (!$login))
      {
        $msg="Eroare FTP!!";

creates the passive connection that is otherwise turned off. It prohibits transfers unless you have a username and password that allows you to connect (a security issue).

As to the issue of points, I don't care about them; you can always post a question in Community Support asking for a refund, although I do think you should suggest that this question be kept because you did post your solution. Make sure you give them the URL to this question.

ep
0
 
ee_ai_constructCommented:
Question answered by asker or dialog valuable.
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now