PHP - FTP import

Aus Wikizone
Version vom 11. April 2019, 14:26 Uhr von 37.49.72.8 (Diskussion) (Die Seite wurde neu angelegt: „Beispiel Gesundheitsregion (TYPO3) <syntaxhighlight lang="php"> function getRemoteFile($myFile,$myUser,$myPass){ /*Reads the file content into $this->arrLin…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Beispiel Gesundheitsregion (TYPO3)

function getRemoteFile($myFile,$myUser,$myPass){
		/*Reads the file content into $this->arrLines*/

		// check if ftp
		//debug(substr($myFile,0,3));
		if(substr($myFile,0,6) == 'ftp://'){
			$pathParts = explode('/',$myFile,4);
			debug($pathParts,"Path Parts");
			$ftp_server = $pathParts[2];
			$sourceFile = $pathParts[3];
			//$targetFile = "tempCsv.csv";
			//debug(t3lib_div::getFileAbsFileName('uploads/gbimporter/'),"DIR");
			//$targetFile = $_SERVER['DOCUMENT_ROOT'].'/temp/tempCsv.csv';
			$targetFile = t3lib_div::getFileAbsFileName('uploads/tx_gbimport/').'tempCsv.csv';
			// Connection
			$conn_id = ftp_connect($ftp_server);
			$login_result = ftp_login($conn_id, $myUser, $myPass);
			if(! $login_result){
				debug($pathParts,"FTP Verbindung gescheitert !");
				$this->messages[] = '<br>FTP Verbindung gescheitert !';
				continue;
			}
			debug(ftp_pwd($conn_id),"FTP Verbindung erfolgreich");
			$this->messages[] = '<br>FTP Verbindung erfolgreich !';
			// GET FILE
			ftp_pasv($conn_id,true);
			$ftpSuccess = ftp_get($conn_id,$targetFile,$sourceFile,FTP_ASCII);
			if($ftpSuccess) $this->messages[] = '<br>FTP Datei geladen';
			else {
				$this->messages[] = '<br>FTP Datei nicht erstellt !<br>';
			}
			/*ob_start();
			$ftpSuccess = ftp_get($conn_id,"php://output", "dtregionna.csv", FTP_BINARY);
			$csvData = ob_get_contents();
			ob_end_clean();
			debug($csvData,"CSV");*/

			//debug($ftpSuccess, "FTP Download:");
			ftp_close($conn_id);
			$fullPath = $targetFile;
		}else{ // HTTP download
			if(!empty($myUser)){// include authentication data
				$fullPath=str_replace("http://", "http://$myUser:$myPass@",$myFile);
			}else{
				$fullPath = $myFile;
			}
		}

		//debug($fullPath,"fullPath");
		$row = 0;
		if($handle = fopen($fullPath, "r")){
//...