Jump to content

download from FTP server/upload to another location??


TFD3

Recommended Posts

I am using a free public FTP server:

ftp://tgftp.nws.noaa.gov/SL.us008001/DF.of/DC.radar/DS.p37cr/

 

What im wanting to do:

Download all folders within the DS.p37cr folder and upload them to a folder on my server.

Each folder contains a file called sn.last that i need copied into the folders on my server.

Is there a way to do this?

 

Thanks !!

Im using this script but getting an error:

 

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home2/alabamaw/public_html/scripts/stormtrack/ftp.php on line 18

 

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home2/alabamaw/public_html/scripts/stormtrack/ftp.php on line 21

 

Warning: ftp_nlist() expects parameter 1 to be resource, boolean given in /home2/alabamaw/public_html/scripts/stormtrack/ftp.php on line 25

Starting 1214097085

 

 

<?
/***************
/*****************************************
           User Options
******************************************/		   
$ftp_server = "ftp://tgftp.nws.noaa.gov";
$ftp_dir = "/SL.us008001/DF.of/DC.radar/DS.p37cr/SI.kbmx/";

$dirLocal = "/rada/";

/************************************************
          DO NOT EDIT BELOW THIS POINT
*************************************************/
	  
// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id);

$dir = $ftp_dir; //Directory on Remote

$contents = ftp_nlist($conn_id, $dir);

echo "Starting ".time()."<br>";

transferFiles($dir, $dirLocal);

function transferFiles($dirRemote, $dirLocal){
global $conn_id;

if ($conn_id != false){

	// get contents of the current directory
	$contents = ftp_nlist($conn_id, $dirRemote);

	foreach($contents as $file){
		$file2 = "$dirRemote/$file";
		$file3 = "$dirLocal/$file";

		if ( (ftp_size($conn_id, $file2) == -1) && !( ($file  == ".") || ($file == "..") ) ){ //Directory
			echo "<b>$file</b><br>";
			mkdir($file3);	//Make Folder
			transferFiles($file2,$file3);
		}
		elseif (ftp_size($conn_id, $file2) > 0) {
			echo "<i>$file</i>";

			//If File Exists Skip.
			if (file_exists($file3)){
				if (ftp_size($conn_id,$file2) == filesize($file3))
					echo "- skipped <br>";
				else {
					ftp_get($conn_id,$file3,$file2,FTP_BINARY,filesize($file3)/9);
					echo "- completed <br>";
				}
			}
			else {
				ftp_get($conn_id,$file3,$file2,FTP_BINARY);
				echo "<br>";
			}

		}
	}
}
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.