function myProcess($values) { global $form; $destination = './uploads/'; // Account FTP on remote server, directory destination, and allows Y/N file overwriting $ftp = array('user' => $values['ftpaccount']['U'], 'pass' => $values['ftpaccount']['P'], 'host' => $values['ftpaccount']['H'], 'dest' => $values['ftpdir'], 'overwrite' => (bool) $values['overwrite']); $result = 'done'; $file =& $form->getElement('tstUpload'); if ($file->isUploadedFile()) { $_ftp = new Net_FTP($ftp['host']); $ret = $_ftp->connect(); if (PEAR::isError($ret)) { $result = $ret->getMessage(); // NET_FTP_ERR_CONNECT_FAILED } else { $ret = $_ftp->login($ftp['user'], $ftp['pass']); if (PEAR::isError($ret)) { $result = $ret->getMessage(); // NET_FTP_ERR_LOGIN_FAILED } else { $_ftp->setPassive(); $ret = $_ftp->cd($ftp['dest']); if (PEAR::isError($ret)) { $result = $ret->getMessage(); // NET_FTP_ERR_DIRCHANGE_FAILED } else { $fval = $file->getValue(); $ret = $_ftp->put($fval['tmp_name'], $fval['name'], $ftp['overwrite']); if (PEAR::isError($ret)) { $result = $ret->getMessage(); // NET_FTP_ERR_UPLOADFILE_FAILED } } } $ret = $_ftp->disconnect(); if (PEAR::isError($ret)) { $result = $ret->getMessage(); // NET_FTP_ERR_DISCONNECT_FAILED } } } // write the semaphore to tell progress meter to stop // in script 'progressbar.php' $semaphore = $destination . $_GET['ID']; $fp = fopen($semaphore, 'w', false); fwrite($fp, $result); fclose($fp); }
head("\$ftp->setPassword(xxx)"); Var_Dump::display($ftp->setPassword($pass)); head("\$ftp->login({$user}, xxx)"); Var_Dump::display($ftp->login($user, $pass)); head("\$ftp->pwd()"); Var_Dump::display($ftp->pwd()); head("\$ftp->ls(null, NET_FTP_DIRS_FILES)"); Var_Dump::display($ftp->ls(null, NET_FTP_DIRS_FILES)); head("\$ftp->mkdir({$baseDir})"); Var_Dump::display($ftp->mkdir($baseDir)); head("\$ftp->cd({$baseDir})"); Var_Dump::display($ftp->cd($baseDir)); head("\$ftp->ls(null, NET_FTP_RAWLIST)"); Var_Dump::display($ftp->ls(null, NET_FTP_RAWLIST)); head("\$ftp->put({$baseDir}{$singleTestFile}, {$singleTestFile})"); Var_Dump::display($ftp->put($baseDir . $singleTestFile, $singleTestFile)); head("\$ftp->ls(null, NET_FTP_FILES_ONLY)"); Var_Dump::display($ftp->ls(null, NET_FTP_FILES_ONLY)); head("\$ftp->put({$baseDir}{$singleTestFile}, {$singleTestFile}, true)"); Var_Dump::display($ftp->put($baseDir . $singleTestFile, $singleTestFile, true)); head("\$ftp->ls(null, NET_FTP_FILES_ONLY)"); Var_Dump::display($ftp->ls(null, NET_FTP_FILES_ONLY)); head("\$ftp->mdtm({$singleTestFile}, 'd.m.Y H:i:s')"); Var_Dump::display($ftp->mdtm($singleTestFile, 'd.m.Y')); head("\$ftp->size({$singleTestFile})"); Var_Dump::display($ftp->size($singleTestFile)); head("\$ftp->get({$singleTestFile}, {$baseDir}{$singleTestFile}, true)"); Var_Dump::display($ftp->get($singleTestFile, $baseDir . $singleTestFile, true)); head("\$ftp->chmod({$singleTestFile}, 700)"); Var_Dump::display($ftp->chmod($singleTestFile, 700)); head("\$ftp->ls(null, NET_FTP_FILES_ONLY)");
/** * The main entry point method. */ public function main() { $project = $this->getProject(); require_once 'Net/FTP.php'; $ftp = new Net_FTP($this->host, $this->port); $ret = $ftp->connect(); if (@PEAR::isError($ret)) { throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage()); } else { $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel); } $ret = $ftp->login($this->username, $this->password); if (@PEAR::isError($ret)) { throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage()); } else { $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel); } if ($this->passive) { $this->log('Setting passive mode', $this->logLevel); $ret = $ftp->setPassive(); if (@PEAR::isError($ret)) { $ftp->disconnect(); throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage()); } } // append '/' to the end if necessary $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/'; if ($this->clearFirst) { // TODO change to a loop through all files and directories within current directory $this->log('Clearing directory ' . $dir, $this->logLevel); $ftp->rm($dir, true); } // Create directory just in case $ret = $ftp->mkdir($dir, true); if (@PEAR::isError($ret)) { $ftp->disconnect(); throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage()); } $ret = $ftp->cd($dir); if (@PEAR::isError($ret)) { $ftp->disconnect(); throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage()); } else { $this->log('Changed directory ' . $dir, $this->logLevel); } $fs = FileSystem::getFileSystem(); $convert = $fs->getSeparator() == '\\'; foreach ($this->filesets as $fs) { $ds = $fs->getDirectoryScanner($project); $fromDir = $fs->getDir($project); $srcFiles = $ds->getIncludedFiles(); $srcDirs = $ds->getIncludedDirectories(); foreach ($srcDirs as $dirname) { if ($convert) { $dirname = str_replace('\\', '/', $dirname); } $this->log('Will create directory ' . $dirname, $this->logLevel); $ret = $ftp->mkdir($dirname, true); if (@PEAR::isError($ret)) { $ftp->disconnect(); throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage()); } } foreach ($srcFiles as $filename) { $file = new PhingFile($fromDir->getAbsolutePath(), $filename); if ($convert) { $filename = str_replace('\\', '/', $filename); } $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel); $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode); if (@PEAR::isError($ret)) { $ftp->disconnect(); throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage()); } } } $ftp->disconnect(); $this->log('Disconnected from FTP server', $this->logLevel); }
$f->disconnect(); die($ret->getMessage()); } // // 6. attachs an instance of the FTP/Progress subclass observer // $observer = new Observer_ProgressUpload($meter); $ok = $f->attach($observer); if (!$ok) { die('cannot attach a FTP Observer'); } // // 7. moves files on the FTP server // foreach ($files as $file) { $ret = $f->put($file, basename($file), $overwrite); if (PEAR::isError($ret)) { if ($ret->getCode() == NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN and !$overwrite) { printf('%s <br />', $ret->getMessage()); continue; // it is just a warning when \$overwrite variable is set to false } die($ret->getMessage()); } printf('<b>%s</b> transfer completed <br />', basename($file)); } $f->detach($observer); // // 8. checks if files are really on the FTP server // $ret = $f->ls(null, NET_FTP_RAWLIST);