I have been working on this for days and I have tried many different methods. What I have now at least starts to transfer the .zip
file, however, there is nothing in it, just the name of the file.
I have this to connect to the server (server a) that the file is on:
<?php
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
header('Content-Type: application/zip');
ini_set('display_errors',"1");
require_once('ftp.php');
// set up basic connection
$conn_id = ftp_ssl_connect($ftp_server);//ftp_connect
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// check connection
if ((! $conn_id ) || (! $login_result )) {
echo "FTP connection has failed!" ;
exit;
} else {
echo "Connected for user $ftp_user_name" ;
echo "<br/>";
}
?>
This all works fine and echo's the username. To transfer the .zip
file itself I'm using:
// using curl to get file
$url = $file;
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
This will put the file name in the remote folder (server b) but there is nothing in it, the size is 0 bytes. How do I get the transfer of the entire file so that I can extract it and use the information?