PHP Script Forums » General Web Development Forum

cURL FTP Upload

(10 posts)

Tags:

  • Started 7 months ago by bubbasheeko
  • Latest reply from bubbasheeko
Please support us by buying these products:

  1. User has not uploaded an avatar

    bubbasheeko
    Member

    I can't seem to figure this out. Using the code you published I keep receiving the error:

    error code 6 (my handler identifies the error)

    The code:

    if (isset($_POST['file_name'])) {
    		 if (!empty($_FILES['file_name']['name'])) {
    			$ch = curl_init();
    			$localfile = $_FILES['file_name']['tmp_name'];
    			$fp = fopen($localfile, 'r');
    			curl_setopt($ch, CURLOPT_URL, 'ftp://loginname@domain.com:password@ftp.domain.com/'. $directory_result['directory'] . '/' . $_FILES['file_name']['name']);
    			curl_setopt($ch, CURLOPT_UPLOAD, 1);
    			curl_setopt($ch, CURLOPT_INFILE, $fp);
    			curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
    			curl_exec ($ch);
    			$error_no = curl_errno($ch);
    			curl_close ($ch);
    				if ($error_no == 0) {
    					$error = 'File uploaded succesfully.';
    				} else {
    					$error = 'There was an error uploading your file.  Please refer to error code '. $error_no . '.';
    				}
    		 } else {
    				$error = 'Please select a file.';
    		 }
    		}

    I want to think it is a problem with the user name - the ftp account is a sub account that requires the @ symbol.

    Any thoughts, any more detail needed let me know

    Kevin

    Posted 7 months ago #
  2. Olaf

    Olaf
    PHP Coder

    maybe the FTP address is wrong? or the directory doesn't exists? or the user has no rights to write?

    Posted 7 months ago #
  3. User has not uploaded an avatar

    bubbasheeko
    Member

    I verified that I could connect to the server through shell access to the server and through windows explorer. It works through both.

    It just won't connect.

    I have verified the output of the variables and they are correct. I created a variable for the directory (ftp://loginname@domain.com:password@ftp.domain.com/'. $directory_result['directory'] . '/' . $_FILES['file_name']['name'])

    This the output:
    ftp://username@domain.com:password@ftp.domain.com/directory/file.txt

    If I connect to the ftp server with the username and login it brings me to directory that has only one directory - in the case of the example - directory is the only folder here.

    Posted 7 months ago #
  4. Olaf

    Olaf
    PHP Coder

    then it should be the first @ sign...

    what happens if you put this row into your browser/explorer bar?

    ftp://username@domain.com:password@ftp.domain.com/directory/file.txt

    Posted 7 months ago #
  5. User has not uploaded an avatar

    bubbasheeko
    Member

    I received:

    Windows cannot find 'ftp://username@domain.com:password@ftp.domain.com/directory'
    Check the spelling and try again.

    (I don't have a file on there as of yet)

    I did try using the main ftp account - the account's root account - it connected using the above format (ftp://login:password@domain.com).

    What can I do to have it accept that there is an @ symbol in the user name?

    Posted 7 months ago #
  6. Olaf

    Olaf
    PHP Coder

    I think nothing the @ character is very important in this address.

    why not use the main account? you can put this script into a .htaccess protected directory, so no one else than you is able to access the script

    Posted 7 months ago #
  7. User has not uploaded an avatar

    bubbasheeko
    Member

    I was thinking the same thing. I couldn't think of anything to bypass the @. It's too bad I wasn't on a Windows server...could have switched the first ampersand to %40 and that would have worked.

    I didn't really want to use the 'root' account to do this, but it is more apparent that I will have to. I would use the .htaccess file to protect this directory, but I cannot because of the nature of the system - it is for uploading presentations for organizations so it will be accessed by a few different organizations - many being a little computer illiterate. So I have had to go with a special session key and a php login form to protect this part of the system and make a bit easier for those illiterate users.

    Thanks for you assistance on this. Great script!

    Posted 7 months ago #
  8. User has not uploaded an avatar

    bubbasheeko
    Member

    I guess I am not quite done with the need of your assistance.

    The largest file that will be uploaded will be set at 20MB.

    I just attempted to upload an 18MB file and received error 26. Which is a read error or read call back error. If you know, how can I resolve this?

    It's funny that there are several pages out there that show the error codes, but none that really show how to resolve them - or what the cause may be.

    Thanks again!

    Kevin

    Posted 7 months ago #
  9. Olaf

    Olaf
    PHP Coder

    maybe some memory limit?

    I use the script on linux systems with much bigger files (> 100mb)

    I think that a lot of your problems are related to a non professional webserver...

    Posted 7 months ago #
  10. User has not uploaded an avatar

    bubbasheeko
    Member

    LOL...my bad...I hadn't changed my file upload size to 25MB. Fixed.

    Posted 7 months ago #

RSS feed for this topic

Reply

You must log in to post.