Upload Via FTP – an alternative to move_uploaded_file

This is a useful function if you want to transfer files between SERVERS.

NOTE : sometimes you wish to transfer files between two servers… or if you have built a CMS and you want ot install the program on a clients server, it is advisable to transfer files by FTP rather than the move_uplaoded_file. This function accepts a parameet — location of the file

function uploadFileFTP($FileName) {
//connect to the ftp server
$conn_id = ftp_connect(FTP_SERVER_ADDRESS);

// login with username and password
$login_result = ftp_login($conn_id, FTP_USER, FTP_PASSWORD);

// check connection
if ((!$conn_id) || (!$login_result)) {
error=“FTP connection has failed!<br>Attempted to connect to “.FTP_SERVER.” for user : “.FTP_USER;

//skip these two steps if you dont want to change the working directory
ftp_chdir($conn_id, “wwwroot”);
ftp_chdir($conn_id, “my_folder”);

// upload the file
$upload = ftp_put($conn_id, $FileName, $source_file, FTP_BINARY);if (!

$upload) {
error=“FTP upload has failed!”;
} else {


2 responses to “Upload Via FTP – an alternative to move_uploaded_file

  1. hi! …
    i want to upload my external wordpress theme on my wordpress blog via http://ftp…???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s