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