我在互联网上搜索了很多,但没有找到解决方案。
我需要通过 PHP 将文件上传到 FTP 服务器。
我测试了各种 PHP 脚本,如下所示,但我总是收到相同的问题(我尝试使用绝对路径、正常路径和其他路径):
连接的
警告:ftp_put():无法打开该文件:第 20 行 /web/htdocs/www.stanem.it/home/csv/importinnovacsv.php 中没有此类文件或目录
上传 /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:[email protected] /cdn-cgi/l/email-protection';
// 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;
}
}
The $remote_file
的论证ftp_put https://www.php.net/manual/en/function.ftp-put.php is a path to the file在 FTP 服务器上。
你正在通过一个URL(它甚至错过任何路径或文件名)。
它应该是这样的:
$remote_file = "/remote/path/test.csv";
一旦解决了路径问题,您还可能会面临数据连接问题,因为您使用的是默认的活动模式。看PHP ftp_put 失败 https://stackoverflow.com/q/40720260/850848.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)