php - ftp_put():无法打开那个文件:没有那个文件或目录
问题描述
我在互联网上搜索了很多,但我没有找到解决方案。我需要通过 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: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;
}
}
解决方案
的$remote_file
参数ftp_put
是FTP 服务器上文件的路径。
您正在传递一个URL(它甚至会丢失任何路径或文件名)。
它应该是这样的:
$remote_file = "/remote/path/test.csv";
一旦解决了路径问题,您也可能会面临数据连接问题,因为您使用的是默认活动模式。请参阅PHP ftp_put 失败。
推荐阅读
- xml - XSD / XML 引用转义
- azure - ServiceBus Dequeue 触发消息 Unmarshalling Golang custom handler in azure:消息格式
- css - 从 HTML 标记访问 bulma.io 变量
- prolog - Prolog:从列表中创建二叉树
- r - 使用转换表 R 转换值
- r - 如何使用 purrr 旋转嵌套数据框?
- javascript - 为什么 :nth-child() 在 JavaScript 中不起作用?
- javascript - iOS 上的 Safari 不允许视频和视频预览
- haskell - 将列表的列表相乘 Haskell
- azure - 如何在 azure 认知搜索中从每个类别中仅获取一项?