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

Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
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.
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
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
Dave BaldwinFixer of ProblemsCommented:
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.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave,

I'm doing that.

Then I'll get back to the question.

Thanks
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
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
Dave BaldwinFixer of ProblemsCommented:
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.
hieloCommented:
Try:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ftp_server="00.00.0.000";
$ftp_user_name="my_username";
$ftp_user_pass="abcxyz";
$file = "pdfwo/wo212397.pdf";//tobe uploaded
$remote_file = "FWLSCO/pdfwo/wo212397.pdf";

// Extract the directory and the filename from $remote_file
$remote_dir = substr($remote_file,0,strrpos($remote_file,"/"));
$remote_filename = basename($remote_file);



// 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);

ftp_chdir($conn_id, $remote_dir);

// upload a file
$jj = ftp_put($conn_id, $remote_filename, $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);
?>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Excellent, works perfect.

Thanks Dave.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.