✏️ 正在编辑: FtpBradesco.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Banco/Service/FtpBradesco.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Banco_Service_FtpBradesco extends Core_Banco_Service_Ftp { protected $_timeInicial; protected $_ultimoImportado; public function getFile($remoteFile, $localFile) { $pathInfo = pathinfo($remoteFile); //verifica se é um TXT e se o arquivo não já foi importado //e se o arquivo é de um intervalo de 1 dia if( strtolower($pathInfo['extension']) == 'txt' && $this->_ultimoImportado['arquivo'] != $pathInfo['basename'] && $this->getLastModifiedFile($remoteFile) >= $this->_timeInicial ){ //verifica se o arquivo já existe if( !file_exists($localFile) ){ return parent::getFile($remoteFile, $localFile); } elseif( $this->getSizeFile($remoteFile) != filesize($localFile) ){ return parent::getFile($remoteFile, $localFile); } } return null; } public function baixarArquivos($diretorio = '.', $bancoId, $closeConnection = true) { $qtdArquivosBaixados = 0; $dbtableArquivo = null; if( $this->getIsConnected() ){ $this->setModPasv(false); $this->changeDirectory($diretorio); ftp_set_option($this->getConnection(), FTP_TIMEOUT_SEC, 60); $files = $this->listFilesInDirectory(); if( $files && count($files) > 0 ){ //localiza a última importação $dbtableArquivo = new Model_DbTable_ArquivoImportado(); if( !$this->_ultimoImportado ){ $this->_ultimoImportado = $dbtableArquivo->getLastFileImported($bancoId); } $dt = new Zend_Date($this->_ultimoImportado['data_importacao']); $this->_timeInicial = $dt->subDay(1)->getTimestamp(); $diretorioDestino = $this->verificaDiretorioDestino($bancoId); /* Tratar arquivos do FTP */ $dateUltimoArquivo = new Zend_Date($this->_timeInicial); foreach ( $files as $file ) { if( strstr($file, ".TXT") ){ if( strstr($file, "PROMOVE") ){ $quebrarArquivo = explode("_", $file); $dataArquivo = $quebrarArquivo[3]; $dtArquivo = new Zend_Date($dataArquivo, 'dd-MM-yyyy'); } else { $quebrarArquivo = explode("_", $file); $dataArquivo = $quebrarArquivo[2]; $dtArquivo = new Zend_Date($dataArquivo, 'ddMMyy'); } if( $dateUltimoArquivo->isEarlier($dtArquivo) ){ //baixa o arquivo if( $this->getFile($file, $diretorioDestino . '/' . $file) ){ $qtdArquivosBaixados++; } } } } } else { Yuppie_Log::write('Falha na listagem dos arquivos! Possível problema no FTP do Bradesco.', $this, Zend_Log::EMERG); throw new Core_Exception('Falha na listagem dos arquivos! Possível problema no FTP do Bradesco.'); } if( $closeConnection ){ $this->closeConnection(); } } return $qtdArquivosBaixados; } }
💾 保存文件
← 返回文件管理器