ftp_put给出错误尝试处理时参数不正确

时间:2013-06-13 13:13:51

标签: php ftp copy

我有以下语法,我试图将当前本地服务器目录中的文件移动到FTP服务器上。

$source = $csv_filename;
$target = fopen("/LocExports/test.csv", "w");

$conn = ftp_connect("ftp.server.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!'; }

此操作失败,错误为The parameter is incorrect

$csv_filename是本地服务器上文件的名称。它与php文件位于同一文件夹中。

我的目的地有效: http://www.server.co.za/kisv2/xmltest/

任何帮助将不胜感激。

一如既往地谢谢,

更新

根据alex的建议,这里有更新的语法:

$csv_filename = 'export-2013-06-13 15:19:48.csv';
$source = $csv_filename;  //this is a file in the same directory as my php file. full path is... http://www.server.co.za/kisv2/xmltest/export-2013-06-13 15:19:48.csv
$target = '/LocExports/'.$csv_filename; //full path is... ftp://ftp.hulamin.co.za/LocExports/

$conn = ftp_connect("ftp.server.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!'; }

2 个答案:

答案 0 :(得分:1)

像这样摆脱fopen()

$csv_filename = 'test.csv';
$source = '/local/path/to/'.$csv_filename; 
$target = '/LocExports/'.$csv_filename;

$conn = ftp_connect("ftp.server.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!'; }

答案 1 :(得分:1)

要明确一点,因为它反映在另一个答案的评论中:

"The parameter is incorrect"是由无效的目标文件名引起的。确保文件名中没有任何无效字符(斜杠,冒号等)。