Here’s the complete example of a PHP FTP client that connects to a remote server, uploads a file, and downloads a file:
// FTP server details
$ftp_server = "";
$ftp_username = "username";
$ftp_password = "password";
// connect to FTP server
 $conn_id = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
// login to FTP server 
if (@ftp_login($conn_id, $ftp_username, $ftp_password)) { 
echo "Connected as $ftp_username@$ftp_server\n"; 
// upload file to FTP server
$file_to_upload = "local_file.txt"; 
$remote_file_path = "/remote/path/file.txt"; 

if (ftp_put($conn_id, $remote_file_path, $file_to_upload, FTP_ASCII)) {
 echo "File uploaded successfully\n";

// download file from FTP server
$local_file_path = "downloaded_file.txt";
$remote_file_path = "/remote/path/file.txt";
if (ftp_get($conn_id, $local_file_path, $remote_file_path, FTP_BINARY)) {
echo "File downloaded successfully\n";

// close FTP connection

Categorized in: