Re: File Upload using ftp commands

From: David (twofish_at_sbcglobal.net)
Date: 03/09/04


Date: Tue, 09 Mar 2004 01:39:00 GMT

Dude:

Here I am replying to myself on the list so that others won't suffer as
I have. I finally figured out that ftp_put and ftp_fput are running *on
the server* and so don't know anything about the client's file system.
They are putting files from the php server onto some other remote
server. Therefore, the only file they are going to know about is the
temp file that php creates on the fly. Once I changed my code to use the
php tmp file, the upload worked smoothly.

HTH,
David

David wrote:
> Because of limitations of my provider, I am forced to use the ftp
> functions to upload files to my server (the permissions on the server
> will not allow me to load files via php).
>
> I have successfully ported the sample code from php.net to do everything
> BUT upload the file. I can connect. I can log in. I can change
> directories. But the file never uploads. As I note in the code, I have
> tried using ftp_put with the local filename, and I have tried using
> ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.
>
> David
>
> [code]
> ---------------------
> <?php
> $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
> echo "<pre>" . print_r($tmp) . "</pre>";
>
> $upload_form_file = $tmp['name']; // have tried using the tmp_name
> element combined with ftp_fput
> $dest_file = "bob.gif"; // just a name to try
>
> // set up a connection or die
> $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
> $ftp_server"); // works
>
> // try to login
> if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
> echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
> } else {
> echo "Couldn't connect as $ftp_user\n";
> }
>
> echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
> this gives the root
>
> if (ftp_chdir($conn_id, $base_path)) {
> echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
> // this prints /the/path/to/docs
> } else {
> echo "Couldn't change directory\n";
> }
>
> echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
> </p>\n"; // files are listed
>
> if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
> echo "successfully uploaded";
> } else {
> echo "There was a problem while uploading $file\n"; // this always
> triggers
> }
>
> // close the connection
> ftp_close($conn_id);
>
> ?>
> [/code]



Relevant Pages

  • Re: able to upload 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
    ... Maximum size of POST data that PHP will accept. ... I just uploaded a 28 meg file to the server. ... assuming that the upload should have failed, ... The server does have Plesk installed, which I know, in times past, has ...
    (comp.lang.php)
  • Re: risk of chmod 0777
    ... As it's a mutualized server, big images can't be resized in the PHP script due to the memory limit, that's why I do it using a ftp connection in my own program. ... It is a Java applet for easy FTP file upload, the pro version can resize images at the client side, before they are uploaded, which saves upload capacity and reduces server-side processing. ...
    (comp.lang.php)
  • Re: PHP Exploitation
    ... Try to RDP to the server, ... Subject: PHP Exploitation ... By now, i am able to upload php files to a Windows 2003 Server, so i ... Need to secure your web apps NOW? ...
    (Pen-Test)
  • Re: Firefox - Chrome
    ... Thanks David, very useful your help, now i can fix it...also i wish to all ... on the server. ... Perhaps produce new web files and upload them again. ... So please look this page with IE & Firefox and you will undertand what i ...
    (microsoft.public.publisher.webdesign)
  • Re: able to upload 28 meg file, yet php.ini limits posts to 10 megs. What is up with that?
    ... Maximum size of POST data that PHP will accept. ... I just uploaded a 28 meg file to the server. ... assuming that the upload should have failed, ... But I've never seen Plesk undermine the importance of the post_max_size ...
    (comp.lang.php)