PHP Send a file via FTP
I was having some trouble successfully sending files, until I set FTP PASSIVE to true.
$ftp_server="ftp.someserver.net";
$ftp_username="username";
$ftp_password="password";
$ftp_filename="somefiletotransfer.zip";
$ftp_fd = ftp_connect($ftp_server);
$ftp_login = ftp_login($ftp_fd, $ftp_username, $ftp_password );
// check connection
if ((!$ftp_fd) || (!$ftp_login))
die("FTP connection has failed!");
echo "* ftpconnect: success"."\n";
ftp_pasv($ftp_fd, true);
echo "* pwd : ".ftp_pwd( $ftp_fd )."\n";
echo "* ls : " .print_r( ftp_nlist($ftp_fd, "."),true )."\n";
// upload the file
$ftp_upload = ftp_put($ftp_fd, $ftp_filename, $ftp_filename, FTP_BINARY);
ftp_close($ftp_fd);
// check upload status
if (!$ftp_upload)
die("FTP upload has failed!");
echo "* ftpupload: success"."\n";code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)
|