JDT

 

FREE Downloads
Articles
Tutorials

 

Using PHP's FTP Functionality


Sample code showing how to use PHP's FTP functionality to transfer a file from one computer to another.

// Set up FTP variables (sample values are used here)
$host = 'xyz.abcdef.com'; // host where you are going to transfer the file to
$user = 'adcdef.com'; // username to log onto the host
$password = 'shccscb'; // password to log onto the host
$sourcefile = $upfile; // file to be transferred
$targetfile = 'public/'.$upfile; // where it is to be transferred to

// connect to FTP site
$conn = ftp_connect("$host");
if (!$conn)
     {
         echo 'Error: Could not connect to ftp server<br>';
         exit;
     }

echo "Connected to $host.<br><br>";

// log in to target site
@ $result = ftp_login($conn, $user, $password);
if (!$result)
     {
         echo "Error: Could not log on as $user<br>";
         ftp_quit($conn);
     exit;
     }

echo "Logged in as $user<br><br>";

// transfer file to target site

if (ftp_put($conn, $targetfile, $sourcefile, FTP_ASCII)) {

echo "Successfully transferred $sourcefile\n";
     }
else {
     echo "There was a problem while transferring $sourcefile\n";
     ftp_quit($conn);
     exit;
     }

// close the connection
ftp_close($conn);







Go back to PHP Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE accounting / bookkeeping software tool.

Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions