ftp_put():无法打开该文件:没有此类文件或目录 [英] ftp_put(): Can't open that file: No such file or directory

查看:108
本文介绍了ftp_put():无法打开该文件:没有此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上进行了大量搜索,但找不到解决方案.我需要通过PHP将文件上传到FTP服务器.

I search a lot on internet but i don't find a solution. I need upload a file to an FTP server through PHP.

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

I tested various script PHP like this below but I always receive the same problem (I tries with absolute, normal and other path):

已连接
警告:ftp_put():无法打开该文件:/web/htdocs/www.stanem.it/home/csv/importinnovacsv.php中第20行上没有这样的文件或目录
上传/web/htdocs/www.stanem.it/home/csv/test.csv

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

推荐答案

$ remote_file 参数.ftp-put.php"rel =" nofollow noreferrer> ftp_put 是FTP服务器上文件路径.

The $remote_file argument of ftp_put is a path to the file on the FTP server.

您正在传递 URL (甚至会丢失任何路径或文件名).

You are passing a URL (and it even misses any path or file name).

应为:

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


一旦解决了路径问题,由于您正在使用默认的活动模式,因此您也很可能会遇到数据连接问题.请参见 PHP ftp_put失败.

这篇关于ftp_put():无法打开该文件:没有此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆