public function testInstantiable() { $adapter = new Ftp($this->options); $this->assertEquals('example.org', $adapter->getHost()); $this->assertEquals(40, $adapter->getPort()); $this->assertEquals(true, $adapter->getSsl()); $this->assertEquals(35, $adapter->getTimeout()); $this->assertEquals('/somewhere/', $adapter->getRoot()); $this->assertEquals(0777, $adapter->getPermPublic()); $this->assertEquals(00, $adapter->getPermPrivate()); $this->assertEquals(false, $adapter->getPassive()); $this->assertEquals('user', $adapter->getUsername()); $this->assertEquals('password', $adapter->getPassword()); $listing = $adapter->listContents('', true); $this->assertInternalType('array', $listing); $this->assertFalse($adapter->has('not.found')); $this->assertFalse($adapter->getVisibility('not.found')); $this->assertFalse($adapter->getSize('not.found')); $this->assertFalse($adapter->getMimetype('not.found')); $this->assertFalse($adapter->getTimestamp('not.found')); $this->assertFalse($adapter->write('write.fail', 'contents')); $this->assertFalse($adapter->writeStream('write.fail', tmpfile())); $this->assertFalse($adapter->update('write.fail', 'contents')); $this->assertFalse($adapter->setVisibility('chmod.fail', 'private')); $this->assertTrue($adapter->rename('a', 'b')); $this->assertTrue($adapter->delete('a')); $result = $adapter->read('something.txt'); $this->assertEquals('contents', $result['contents']); $result = $adapter->getMimetype('something.txt'); $this->assertEquals('text/plain', $result['mimetype']); $this->assertFalse($adapter->createDir('some.nested/mkdir.fail')); $this->assertInternalType('array', $adapter->write('unknowndir/file.txt', 'contents', 'public')); $this->assertInternalType('array', $adapter->writeStream('unknowndir/file.txt', tmpfile(), 'public')); $adapter->deleteDir(''); $this->assertInternalType('array', $adapter->getTimestamp('some/file.ext')); }
/** * Uploades files. * @return void */ private function uploadFiles(array $files) { $root = $this->ftp->pwd(); $root = $root === '/' ? '' : $root; $prevDir = NULL; $toRename = array(); foreach ($files as $num => $file) { $remoteFile = $root . $file; $remoteDir = dirname($remoteFile); if ($remoteDir !== $prevDir) { $prevDir = $remoteDir; if (trim($remoteDir, '\\/') !== '' && !$this->ftp->isDir($remoteDir)) { $this->ftp->mkDirRecursive($remoteDir); } } if (substr($remoteFile, -1) === '/') { // is dir? continue; } $localFile = $this->preprocess($orig = ".{$file}"); if (realpath($orig) !== $localFile) { $file .= ' (filters was applied)'; } $toRename[] = $remoteFile; $size = filesize($localFile); $retry = self::RETRIES; upload: $blocks = 0; do { $this->writeProgress($num + 1, count($files), $file, min(round($blocks * self::BLOCK_SIZE / max($size, 1)), 100)); try { $ret = $blocks === 0 ? $this->ftp->nbPut($remoteFile . self::TEMPORARY_SUFFIX, $localFile, Ftp::BINARY) : $this->ftp->nbContinue(); // Ftp::AUTORESUME } catch (FtpException $e) { $this->ftp->reconnect(); if (--$retry) { goto upload; } throw new Exception("Cannot upload file {$file}, number of retries exceeded."); } $blocks++; } while ($ret === Ftp::MOREDATA); $this->writeProgress($num + 1, count($files), $file); } foreach ($toRename as $num => $file) { $this->writeProgress($num + 1, count($toRename), "Renaming {$file}"); $this->ftp->tryDelete($file); $this->ftp->rename($file . self::TEMPORARY_SUFFIX, $file); // TODO: zachovat permissions } }
/** * Cambia el nombre de una imagen existente * * Actualiza el nombre nuevo en la tabla de imagenes y cambia * el nombre al archivo físico * * @param string $titulo El titulo de la imagen * @param string $slug El nombre de la imagen sin limpiar * @param booelan $mostrarPieFoto TRUE si se quiere mostrar el titulo en el pie de la imagen * @param array $documento Array con los parametros del documento * @param booelan $idThumbnail * @param integer $orden * @return boolean TRUE si se cambió con Exito */ public function actualiza() { $ok = TRUE; // Cargo los datos del objeto antes de cambiarlos $doc = new CpanDocs($this->getId()); $pathName = $doc->getPathName(); $nombreAnterior = $doc->getName(); unset($doc); // Si el nombre propuesto es distinto al que ya tiene y no es Thumbnail // recalculo el nombre amigable, cambio el path y renombro el archivo $this->actualizaNombreAmigable(); $nombreNuevo = $this->getName(); $pathInfo = pathinfo($pathName); $carpetaDestino = $this->_prePath . $pathInfo['dirname']; $ftp = new Ftp($_SESSION['project']['ftp']); $ok = $ftp->rename($carpetaDestino, $nombreAnterior, $nombreNuevo); $this->_errores = $ftp->getErrores(); $ftp->close(); unset($ftp); if ($this->_ArrayDoc['tmp_name'] != '') { $ok = $this->subeDocumento(); } // Si todo ha ido bien, actualizo el objeto if ($ok) { $this->save(); } unset($this); return $ok; }