Inebriated Software
PHP FTP Client

Release 2.2, March 12, 2002

Author: Paul Southworth <phpftp@inebria.com>

This is an FTP client implemented in PHP. It is freely distributed under a BSD-style copyright, which you will find in the source. You can view the source if you like. Or you can download it. There are some variables to edit in the source - please read it.

If you're using PHP 3, you must have version 3.0.17 or higher to run this software. If you're using PHP 4, you must have 4.0.3 or higher.

If this software is useful to you, please go make yourself an account on Freshmeat and rate this software here: http://freshmeat.net/projects/phpftp/

And here too: http://www.hotscripts.com/Detailed/4582.html

If you're having problems using it, please read the FAQ. Like most people who give away free software, I'm sorry the documentation isn't better, I'm sorry the interface isn't prettier, and I apologize in advance if I don't answer your e-mail promptly.

Here is a screenshot of version 2.1.

I wrote this software because I was tired of explaining how to set up SSH tunnels for FTP. Unlike most other file upload scripts, phpftp requires no special privileges to make uploaded files owned by the user who uploaded them - this service is performed by the FTP server.

New in version 2.2
Added more configurable items, such as the temporary directory and the maximum upload file size, since users seem to be changing these values frequently. Fixed nasty easily-exploited security hole in phpftp_put() function. This creates a dependency on the is_uploaded_file() PHP function. PHP 3 users must have version 3.0.17 or higher, and PHP 4 users must have version 4.0.3 or higher in order to have that function. Users will not notice any new functionality in the 2.2 release - no features have been added.

New in version 2.1
The parser has been updated to work with D. J. Bernstein's EPLF FTP server directory listing format. This should allow phpftp to interoperate with the anonftp and publicfile FTP servers. This also required a change to how we send the FTP rawlist command - prior to version 2.1 we asked for a rawlist of "." and now we ask for a rawlist with no arguments. No other changes or fixes in this version.

New in version 2.0
There is now a directory parser that examines a raw directory listing and figures out if items are files, directories, or symlinks. The caveat for release 2.0 is that symlinks are identified, but are ignored and do not appear in the client. Additionally, there is an optional feature to do MIME type lookups and send the proper MIME information to the downloading browser. This creates a dependency on my mime_lookup() function library. I repeat, this is optional and you can use phpftp without it. Download the MIME lookup library here: http://inebria.com/mime_lookup/. Version 2.0 of phpftp has only been tested with PHP 4.0.4p1. Browsers tested so far are Konqueror 2.1.1, MS IE 5.0, Mozilla 0.9.3, Netscape 4.78.

New in version 1.6
WARNING: there is a rogue release of this software called version 1.6. I don't know who wrote it. Please don't confuse it with the official release - which can only be found on this web site. There is no official release of phpftp with a version number of 1.6.

New in version 1.5
Fixed critical bug in phpftp_put() function. Did a lot of code cleanup.

New in version 1.4
Bug fixes and enhancements contributed by Lars Anderson, and a mkdir function written by myself.

New in version 1.3
Fixed a bug in phpftp_put() reported by Fabrice Métayer.

New in version 1.2
I have cut up the functions into smaller pieces to reduce redundancy in the code, and I have added error control in a number of places, which should keep it from spewing PHP errors and warnings in end users' faces.

Here is a brief FAQ on the software.

  1. Why does it give an error "Fatal error: Call to unsupported or undefined function ftp_connect()"? Or Why do I get a blank page after the login?
    You failed to compile PHP with the FTP functions. You need PHP 3.0.13 or higher, and you must configure it with the --with-ftp flag. Go to the PHP web site for help with that. This is the number one most common problem people have with the software. No, I will not tell you how to compile PHP.
     
  2. Why do uploads fail with big files?
    You may need to edit your php.ini or php3.ini file and increase the value of upload_max_filesize. You may need to restart your web server after this change. Additionally, may need to adjust the max_file_size variable in the script.
     
  3. Does it work with PHP4?
    Yes. It is now only tested on PHP4 and may eventually break for PHP3 users due to lack of testing.
     
  4. Your code is so ugly. Are you a drunken sysadmin or something?
    Guilty as charged. What do you want? Pity?
     
  5. You write bad HTML too.
    Not a web designer either. See previous question.
     
  6. How can I make it FTP to something other than localhost?
    Change $phpftp_host="localhost"; to whatever you want.
     
  7. Where does it write temporary files?
    /var/tmp/xfers. Make sure that directory exists, and is readable and writable only by the user your web server runs as. If your web server runs as the "httpd" user, make "httpd" own the /var/tmp/xfers directory and make it mode 0700. You may want to set up a cron job to clean that directory periodically, since aborted file operations may leave turds in it.
     
  8. Omigod it's sending users' passwords in the HTML forms!!
    Exactly. Allow me to point out that FTP isn't secure either. I only run this software in an SSL environment and have it make connections to the loopback interface. I encourage you to do the same. If you don't, life will probably bite you on the ass eventually.
     
  9. It seems to have problems transmitting passwords with strange characters in them.
    I think this should be fixed as of version 1.5
     
  10. How can I make it lock the user in their home directory?
    That is the job of an FTP server, not a client. This is a client.
     
  11. When will you add the feature I want?
    Feel free to ask, but my development work on this is primarily driven by my own needs.
     
  12. Why do unreadable files appear as directories?
    NEW! This problem is solved with the addition of a parser in version 2.0. This FAQ item only applies to pre-2.0 releases.

    My scheme for determining whether an item in a directory listing is a file or a directory (or a symlink to a file or directory) was by calling ftp_size() on each item. Unfortunately if a file is unreadable, it returns the same value as a directory does.
     

  13. Symlinks don't work!
    True - symlinks are broken in version 2.0 - the parser needs more work.
     
  14. Why are all downloaded files named "ftp.php"? Or, why does my browser "view" files that ought to be downloaded?
    This is almost always a browser problem. I am not an expert on all (or any) browsers, but here are some clues that may help you. Browsers that don't do the right thing usually do not properly support the Content-Disposition header. You can read about that in RFC 2183. I believe IE 4.x cannot support the Content-Disposition header at all. There is a bad IE 5.5 bug fixed in IE 5.5 SP1. There is a bug in IE 5.0 which is fixed in IE 5.01 - only affects downloads for file types that IE doesn't know about. KDE Konqueror won't work right either, at least through version 2.1.1 - newer versions may be fixed - see bug #13854. Netscape 4.7x seems to work well. MSIE 5.01 on Windows seems to work OK. Mozilla is OK but loses the file name if you do a 'Save As'.