FTP Download

PHP Beispiel um Dateien per FTP herunter zu laden.

download.php
<?php
 
$ftp_server="test.de";
$ftp_port="44021";
$ftp_user_name="username";
$ftp_user_pass="wwrjmeb2";
$file = "";//tobe uploaded
$remote_file = "";
 
// set up basic connection
$conn_id = ftp_connect($ftp_server,$ftp_port);
 
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
 
// check connection
if ((!$conn_id) || (!$login_result)) {
    die("FTP-Verbindungsaufbau ist fehlgeschlagen!");
}
 
echo "Aktuelles Verzeichnis: " . ftp_pwd($conn_id) . "<br>";
 
// Versuche, in das Verzeichnis "outbound" zu wechseln
if (ftp_chdir($conn_id, "outbound")) {
    echo "Aktuelles Verzeichnis: " . ftp_pwd($conn_id) . "<br>";
} else {
    echo "Verzeichniswechsel ist fehlgeschlagen.<br>";
}
 
// check for *.xml files
$ftp_nlist_root = ftp_nlist($conn_id, "*.xml");
 
//if (isset($ftp_nList_root)){				// nur wenn Dateien vorhanden sind
 
	foreach ($ftp_nlist_root as $file) {
		$mod = ftp_mdtm($conn_id, $file);
		echo $file."<br>";
		if (!ftp_get($conn_id, $file, $file, FTP_ASCII)){
			echo "Fehlder beim Download";
		} else {
			echo $file." downloaded<br>";
			/*
			if (ftp_delete($conn_id, $file)) {
				echo "$file deleted successful<br>";
			} else {
				echo "$file could not delete <br>";
			}
			echo "<hr>";
		*/
		}
	}
//}
 
 
 
// close the connection
ftp_close($conn_id);
?>