add FTP Upload

This commit is contained in:
Marko
2023-09-26 17:11:51 +02:00
parent 30b675e999
commit a05da31f8f
4 changed files with 939 additions and 549 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -78,24 +78,25 @@ class Ftp
*/ */
public function uploadFile(string $localFile): bool public function uploadFile(string $localFile): bool
{ {
#dd(array($localFile,$this->getHost(),$this->getUser(), $this->getPassword(),$this->getRemoteDir())); $ftp = ftp_ssl_connect($this->getHost(),$this->getPort());
$sftp = new SFTP($this->getHost(),$this->getPort()); $ftp_login = ftp_login($ftp,$this->getUser(), $this->getPassword());
$sftp_login = $sftp->login($this->getUser(), $this->getPassword()); ftp_pasv($ftp, true);
//dump(array('$sftp_login'=>$sftp_login,'Line'=>__LINE__,'Method'=>__METHOD__));
$remoteFile = 'order_'.date('YmdHis').'.csv'; $remoteFile = 'stock_'.date('YmdHis').'.csv';
if($sftp_login){
$r = $sftp->put($this->getRemoteDir().$remoteFile.'.tmp', $localFile, SFTP::SOURCE_LOCAL_FILE); if($ftp_login){
//dump(array('$r'=>$r,$this->getRemoteDir().$remoteFile, $localFile,'Line'=>__LINE__)); $r = ftp_put($ftp,$this->getRemoteDir().$remoteFile, $localFile);
ftp_close($ftp);
// dump(array('$r'=>$r,$this->getRemoteDir().$remoteFile, $localFile,'Line'=>__LINE__));
if($r){ if($r){
if($sftp->rename($this->getRemoteDir().$remoteFile.'.tmp',$this->getRemoteDir().$remoteFile)) // if(ftp_rename($ftp,$this->getRemoteDir().$remoteFile.'.tmp',$this->getRemoteDir().$remoteFile)){
// ftp_close($ftp);
return unlink($localFile); # löschen der datei return unlink($localFile); # löschen der datei
else //}
return false;
}else }else
return false; return false;
} }
return false; return false;
} }
} }

View File

@@ -127,17 +127,17 @@ class HiltesImport
$c = 0; $c = 0;
while (!$file->eof()) { while (!$file->eof()) {
#*** Convertiert die Zeile in UTF8 // #*** Convertiert die Zeile in UTF8
$data = iconv('ISO-8859-1','UTF-8',$file->fgets()); // $data = iconv('ISO-8859-1','UTF-8',$file->fgets());
//
#*** Überspringt die erste Zeile // #*** Überspringt die erste Zeile
if($c == 0){ // if($c == 0){
$c++; // $c++;
continue; // continue;
} // }
#*** Speichert die Zeile #*** Speichert die Zeile
$this->switchSaveData($this->splitLine($data)); $this->switchSaveData($this->splitLine($file->fgets()));
$c++; $c++;
} }

View File

@@ -87,7 +87,14 @@ class Jtl
{ {
try { try {
$writer = Writer::createFromPath(getcwd().'/jtl/cds-export.csv', 'w+'); $writer = Writer::createFromPath(getcwd().'/jtl/cds-export.csv', 'w+');
$writer->insertAll(new \ArrayIterator($data)); $bytes = $writer->insertAll(new \ArrayIterator($data));
if($bytes){
$this->logger->info('Exported '.$bytes.' bytes');
$FTP = new Ftp();
$FTP->uploadFile(getcwd().'/jtl/cds-export.csv');
}
}catch (\Exception $e){ }catch (\Exception $e){
$this->logger->error($e->getMessage()); $this->logger->error($e->getMessage());
@@ -95,4 +102,6 @@ class Jtl
} }
} }