dongwang6837
2013-06-13 14:30
浏览 108
已采纳

将csv文件上传到ftp服务器 - 文件为空

I am trying to store a file from my local server on an ftp server.

source file is in my current directory (same as php file)

I run the script with http://www.server.co.za/kisv2/xmltest/export.php

file to upload to ftp is http://www.server.co.za/kisv2/xmltest/exportfile.csv

destination ftp path is: ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv

my ftp login defaults to: ftp://ftp.ftpserver.co.za

so I want to copy file from in current directory exportfile.csv to ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv

My Current syntax is:

$source = 'exportfile.csv';  //this is a file in the same directory as my php file. full path is... http://www.server.co.za/kisv2/xmltest/exportfile.csv
$target = '/LocExports/exportfile.csv'; //full path is... ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv

$conn = ftp_connect("ftp.ftpserver.co.za") or die("Could not connect");
ftp_login($conn, "username", "password");

$upload = ftp_put($conn, $target, $source, FTP_ASCII);
if (!$upload) { echo 'FTP upload failed!'; }

echo "complete";

This gives me error Warning: ftp_put() [function.ftp-put]: Opening ASCII mode data connection. the file does appear on the FTP server but is blank and 0bytes in size.

Any ideas welcome.

Thanks and regards

UPDATE

$source = 'exportfile.csv';  
$target = '/LocExports/exportfile.csv'; 

$conn = ftp_connect("ftp.server.co.za") or die("Could not connect");
ftp_login($conn, "username", "password");

ftp_pasv($conn, true); 

$upload = ftp_put($conn, $target, $source, FTP_BINARY);
if (!$upload) { echo 'FTP upload failed!'; }

echo "complete";

this still fails with: Warning: ftp_put() [function.ftp-put]: Opening BINARY mode data connection.

file is created on ftp but empty.

thanks again

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将本地服务器上的文件存储在ftp服务器上。

源文件位于我当前的目录中(与php文件相同)

我使用 http://www.server.co.za/kisv2/xmltest运行脚本 /export.php

nn

要上传到ftp的文件是 http://www.server.co.za/kisv2/xmltest/exportfile.csv

目标ftp路径为: ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv 我的ftp登录默认为: ftp://ftp.ftpserver.co.za

所以我想复制当前目录中的文件 exportfile.csv ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv

My Current语法为:

  $ source ='exportfile.csv';  //这是一个与我的php文件在同一目录下的文件。 完整路径是... http://www.server.co.za/kisv2/xmltest/exportfile.csv
$target ='/ LexExports / exportfile.csv';  //完整路径是... ftp://ftp.ftpserver.co.za/LocExports/exportfile.csv

$conn = ftp_connect(“ftp.ftpserver.co.za”)或死(“不能 connect“); 
ftp_login($ conn,”username“,”password“); 
 
 $ upload = ftp_put($ conn,$ target,$ source,FTP_ASCII); 
if(!$ upload){echo'  FTP上传失败!';  } 
 
echo“完成”; 
   
 
 

这给了我错误警告:ftp_put()[function.ftp-put]:打开ASCII模式数据 连接。 该文件确实出现在FTP服务器上,但是空白且大小为0字节。

欢迎任何想法。

谢谢和问候 \ n

UPDATE

  $ source ='exportfile.csv';  
 $ target ='/ LocExports / exportfile.csv';  
 
 $ conn = ftp_connect(“ftp.server.co.za”)或死亡(“无法连接”); 
ftp_login($ conn,“用户名”,“密码”); 
 
ftp_pasv($  conn,true);  
 
 $ upload = ftp_put($ conn,$ target,$ source,FTP_BINARY); 
if(!$ upload){echo'FTP upload failed!';  } 
 
echo“完成”; 
   
 
 

这仍然失败: 警告:ftp_put()[function.ftp-put]:打开 BINARY模式数据连接。

文件在ftp上创建但是为空。

再次感谢

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanrebo3559 2013-06-13 14:33
    已采纳

    Add ftp_pasv($conn, true); after your ftp_login(...) .

    From http://www.php.net/manual/en/function.ftp-put.php

    If when using ftp_put you get the one of the following errors:

    Warning: ftp_put() [function.ftp-put]: Opening ASCII mode data connection

    Warning: ftp_put() [function.ftp-put]: Opening BINARY mode data connection

    and it creates the file in the correct location but is a 0kb file and all FTP commands thereafter fail. It is likely that the client is behind a firewall. To rectify this use:

    ftp_pasv($conn, true);

    Before executing any put commands. Took me so long to figure this out I actually cheered when I did :D

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题