ftp_put(): 无法打开该文件:没有那个文件或目录

ftp_put(): Can't open that file: No such file or directory

我在互联网上搜索了很多,但没有找到解决方案。 我需要通过 PHP.

将文件上传到 FTP 服务器

我像下面这样测试了各种脚本PHP,但我总是遇到同样的问题(我尝试使用绝对路径、正常路径和其他路径):

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

我必须做什么?

<?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;
   }
} 

ftp_put$remote_file 参数是 [=30= 上的 文件 路径 ] 服务器.

您传递的是 URL(它甚至遗漏了任何路径或文件名)。

应该是这样的:

$remote_file = "/remote/path/test.csv";

解决路径问题后,您还可能会遇到数据连接问题,因为您使用的是默认活动模式。参见