问题
I search a lot on internet but i don't find a solution. I need upload a file to an FTP server through PHP.
I tested various script PHP like this below but I always receive the same problem (I tries with absolute, normal and other path):
connected
Warning: ftp_put(): Can't open that file: No such file or directory in /web/htdocs/www.stanem.it/home/csv/importinnovacsv.php on line 20
There was a problem while uploading /web/htdocs/www.stanem.it/home/csv/test.csv
What I have to do?
<?php
$ftp_server="ftp.xxxx.it";
$ftp_user_name="user";
$ftp_user_pass="psw";
// connect and login to FTP server
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
if($login) {
echo 'connected<br>';
// Where I need to put file
$local_file = '/web/htdocs/www.stanem.it/home/csv/test.csv';
// Where I copy the file
$server_dir = 'ftp://15886:XDBbcFYQUs@ftp.innovaspa.it';
// upload a file
if (ftp_put($ftp_conn, $server_dir, $local_file, FTP_ASCII)) {
echo "successfully uploaded $local_file\n";
exit;
} else {
echo "There was a problem while uploading $local_file\n";
exit;
}
}
回答1:
The $remote_file
argument of ftp_put is a path to the file on the FTP server.
You are passing a URL (and it even misses any path or file name).
It should be like:
$remote_file = "/remote/path/test.csv";
Once you resolve the path problem, you will also likely face data connection problems, as your are using the default active mode. See PHP ftp_put fails.
来源:https://stackoverflow.com/questions/65940149/ftp-put-cant-open-that-file-no-such-file-or-directory