PHP has built in networking api to access all kinds of services. Here is a script you can type in a command line window to upload a folder and all its sub directories to a FTP server. Sometimes it will be very handy with a command to do this kind of job.

 
 
<?php
 
$connection = ftp_connect('14.81.208.80'); // ftp server ip address
$login = ftp_login($connection,"username","pass");
 
 
if ((!$connection) || (!$login)) {
    echo 'Connection Failed!!!<BR>\n';
    return false;
} 
else
{
    echo "connection success\n";
}
 
 
if($argv[1] == '')
  $uploadpath = getcwd();
else
  $uploadpath = realpath($argv[1]);
 
ftpupload($connection,$uploadpath);
 
ftp_close($connection);
 
function ftpupload($connection,$path)
{
    $s = $path;
    $s = str_replace('\\','/',$s);
    $s = strstr($s,"/mysite");
    $s = "/webdir".$s;
 
    if(is_dir($path))
    {
        if(ftp_mkdir($connection,$s))
            {echo "successfully created $s\n";}
        else
            {echo "mkdir $s fails\n";}
 
        $d = dir($path);
        while(($entry = $d->read()) !== FALSE)
        {
            if (($entry!=".")&&($entry!=".."))
            {
                if(is_dir("$path/$entry"))
                {
                    ftpupload($connection,"$path/$entry");
                }
                else
                {
                    if(ftp_put($connection,"$s/$entry","$path/$entry",FTP_BINARY))
                        {echo "upload file $s/$entry sucess\n";}
                    else
                        {echo "upload file $s/$entry fail\n";}
                }
              }
 
        }        
    }
    else
    {
        if(ftp_put($connection,$s,$path,FTP_BINARY))
            {echo "upload file $s $path sucess\n";}
        else
            {echo "upload file $s $path fail\n";}    
    }
}
?>
 
 
 

You need the FTP server ip address and login name and password to connect your FTP server. Your host provider should give you these information after you buy the web host.

One thing that you may have tweak is how to transfer your local file path to the server path. For example your local site develop directory is F:\projects\mysite, and the server path is /webdir. For a file

 
F:\projects\mysite\index.php
 

The target path should be

 
/webdir/index.php
 

The code at the start of ftpupload do this job:

 
    $s = $path;
    $s = str_replace('\\','/',$s);
    $s = strstr($s,"/mysite");
    $s = "/webdir".$s;
 

Now you can go to your local site folders and type

 
ftpupload.php .
 

It will upload the whole site to the FTP server.

For windows, you may need to associate the php file with the php interpreter. The command line below will create the association:

 
assoc .php=phpfile
ftype phpfile=d:\php\php-5.2.10-Win32\php.exe  "%%1" %%*