Zum Inhalt springen

Datei via PHP von einem FTPS Downloaden

<?php

// FTPS Server Details
$ftps_server = 'ftps://195.4.159.226';
$username = '';
$password = '';

// File to be downloaded
$remote_file = '/items_dg_stock.csv';
$local_file = '/var/www/clients/client0/web14/web/wp-content/uploads/wpallimport/files/items_dg_stock.csv'; //must be adapted

// Open a file in which we write the downloaded file
$fp = fopen($local_file, 'w');

if (!$fp) {
    die("Konnte Datei nicht zum Schreiben öffnen.");
}

// Initialise a cURL handle file write
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $ftps_server . $remote_file);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Set this to true for better security
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_setopt($ch, CURLOPT_FILE, $fp);

// Execute the cURL command
$result = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'cURL Fehler: ' . curl_error($ch);
} else {
    echo 'Datei erfolgreich heruntergeladen.';
}

// Close the cURL handle and the file
curl_close($ch);
fclose($fp);

?>