home   articles   tags   browse code   

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";
 

Tags: php
 


 

 



Related Articles
 


home  |  privacy policy  |  terms of use  |  contact  


©2012, Zedwood.com

zedwood.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com