Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Can't find file using php ftp

See attached. Trying to use this to ftp a file from the host the file resides on to another place.

I get this error message:

Warning: ftp_put(): Can't open that file: No such file or directory in /var/www/vhosts/fwsprinkler.com/fwsprinklercdb.info/php_ftp_test.php on line 17 There was a problem while uploading /var/www/vhosts/fwsprinkler.com/fwsprinklercdb.info/pdfwo/wo212397.pdf , error =

The path specified is the absolute path. I had previously used the relative path from where the php file sits. Same error.

The referenced file is in the folder pdfwo.

What's wrong?

Thanks

<<Added by Mr Wolfe>>
php-ftp-test.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ftp_server="00.00.0.000";
$ftp_user_name="my_username";
$ftp_user_pass="xxxxxxxx";
$file = "/var/www/vhosts/_path_to_/pdfwo/wo212397.pdf";//tobe uploaded
$remote_file = "http://www.rkassoc.org/FWLSCO/pdfwo/wo212397.pdf";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
$jj = ftp_put($conn_id, $remote_file, $file, FTP_ASCII);
if ($jj) {
    echo "successfully uploaded $file\n";
    exit;
} else {
    echo "There was a problem while uploading $file , error = " . $jj;
    exit;
    }
// close the connection
ftp_close($conn_id);
?>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

FTP does not work with absolute paths.  In FTP, you must change to the target directory and 'put' the file by filename.  "http://www.rkassoc.org/" is not an FTP host either.  And you should edit that file because it has your credentials in it.
Avatar of Richard Korts

ASKER

Dave,

Thanks, I didn't think about what was encoded in that file.

Can you delete the attachment (or can I) off of ee?

Thanks
I can't but one of the moderators can.  You may have to change your password which wouldn't be a bad idea right now anyway.
Dave,

I'm doing that.

Then I'll get back to the question.

Thanks
Dave,

OK, I changed the password & made the file path relative.

See attached (password changed).

Same result:

Warning: ftp_put(): Can't open that file: No such file or directory in /var/www/vhosts/fwsprinkler.com/fwsprinklercdb.info/php_ftp_test.php on line 17 There was a problem while uploading pdfwo/wo212397.pdf , error =
php-ftp-test.php
As I said above, FTP will NOT use absolute paths.  You must change to the directory that you want to use for upload or download and then put or get the file (without any path).  You can see that in FTP programs like Filezilla or CoreFTP.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, works perfect.

Thanks Dave.