0

我有以下语法,我试图将当前本地服务器目录中的文件移动到 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!'; }
4

2 回答 2

2

为了清楚起见,因为它被埋在对另一个答案的评论中:

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

于 2013-11-01T15:18:26.123 回答
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!'; }
于 2013-06-13T13:31:16.467 回答