Example #1
0
 public function generate($log)
 {
     global $db;
     $host = "ftp.mozilla.org";
     $hostpos = strpos($this->logURL, $host);
     if ($hostpos === false) {
         throw new Exception("Log file {$this->logURL} not hosted on {$host}!");
     }
     $path = substr($this->logURL, $hostpos + strlen($host) + strlen("/"));
     $ftpstream = @ftp_connect($host);
     if (!@ftp_login($ftpstream, "anonymous", "")) {
         throw new Exception("Couldn't connect to Mozilla FTP server.");
     }
     $fp = tmpfile();
     if (!@ftp_fget($ftpstream, $fp, $path, FTP_BINARY)) {
         throw new Exception("Log not available at URL {$this->logURL}.");
     }
     ftp_close($ftpstream);
     rewind($fp);
     $db->beginTransaction();
     $stmt = $db->prepare("\n      UPDATE runs_logs\n      SET content = :content\n      WHERE buildbot_id = :id AND type = :type;");
     $stmt->bindParam(":content", $fp, PDO::PARAM_LOB);
     $stmt->bindParam(":id", $log['_id']);
     $stmt->bindParam(":type", $log['type']);
     $stmt->execute();
     $db->commit();
     fclose($fp);
 }
Example #2
0
 /**
  * Fetch data file from Itella FTP server
  * @param $type Data file type (PCF = localities, BAF = street addresses, POM = zip code changes)
  * @returns Temp file name
  */
 public function fetchFile($type)
 {
     //Connect to FTP server
     $ftp = ftp_connect($this->host);
     if ($ftp === false) {
         throw new Exception("Could not connect to '{$this->host}'");
     }
     if (!ftp_login($ftp, $this->user, $this->password)) {
         throw new Exception("Login to '{$this->host}' as '{$this->user}' failed");
     }
     //Find filename to download
     ftp_pasv($ftp, true);
     $list = ftp_nlist($ftp, '.');
     $file = null;
     foreach ($list as $item) {
         $parts = explode('_', $item);
         if (isset($parts[0]) && strtoupper($parts[0]) == strtoupper($type)) {
             $file = $item;
         }
     }
     if ($file == null) {
         throw new Exception("'{$type}' file not found");
     }
     //Download requested data file
     $tmpFile = tempnam(sys_get_temp_dir(), 'FinZip_' . $type . '_') . '.zip';
     $this->tmpFiles[] = $tmpFile;
     $tmp = fopen($tmpFile, 'w');
     ftp_pasv($ftp, true);
     ftp_fget($ftp, $tmp, $file, FTP_BINARY);
     ftp_close($ftp);
     fclose($tmp);
     //Return the filename of the temporary file
     return $tmpFile;
 }
 public static function copyFileInStream($path, $stream)
 {
     $fake = new ftpAccessWrapper();
     $parts = $fake->parseUrl($path);
     $link = $fake->createFTPLink();
     $serverPath = AJXP_Utils::securePath($fake->path . "/" . $parts["path"]);
     ftp_fget($link, $stream, $serverPath, FTP_BINARY);
 }
Example #4
0
function ftpGetContents($ftpConn, $filepath, $ftpMode)
{
    // Create temp handler, this type needed for extended char set
    $tempHandle = fopen('php://temp', 'r+');
    // Get file from FTP assuming that it exists
    ftp_fget($ftpConn, $tempHandle, $filepath, $ftpMode, 0);
    // Return our content
    return stream_get_contents($tempHandle, -1, 0);
}
Example #5
0
function ftp_get_string($ftp, $filename)
{
    $temp = fopen('php://temp', 'r+');
    if (@ftp_fget($ftp, $temp, $filename, FTP_BINARY, 0)) {
        rewind($temp);
        return stream_get_contents($temp);
    } else {
        return "Error reading data.";
    }
}
Example #6
0
 /**
  * {@InheritDoc}
  */
 public function read($key)
 {
     $temp = fopen('php://temp', 'r+');
     if (!ftp_fget($this->getConnection(), $temp, $this->computePath($key), FTP_ASCII)) {
         throw new \RuntimeException(sprintf('Could not read the \'%s\' file.', $key));
     }
     rewind($temp);
     $contents = stream_get_contents($temp);
     fclose($temp);
     return $contents;
 }
Example #7
0
 /**
  * {@inheritDoc}
  */
 public function read($key)
 {
     $temp = fopen('php://temp', 'r+');
     if (!ftp_fget($this->getConnection(), $temp, $this->computePath($key), $this->mode)) {
         return false;
     }
     rewind($temp);
     $contents = stream_get_contents($temp);
     fclose($temp);
     return $contents;
 }
 public function executeGetFileAsBinary($loginData, $file)
 {
     $conn = $this->_getConnexion($loginData);
     $tempHandle = fopen('php://temp', 'r+');
     $result = ftp_fget($conn, $tempHandle, $file, FTP_BINARY);
     if ($result !== false) {
         rewind($tempHandle);
         return array('contents' => base64_encode(stream_get_contents($tempHandle)));
     } else {
         throw new \RuntimeException('Cannot open file "' . $file . '"');
     }
 }
 protected function getFileAsBinary($loginData, $file)
 {
     $conn = $this->_getConnexion($loginData);
     $tempHandle = fopen('php://temp', 'r+');
     $result = @ftp_fget($conn, $tempHandle, $file, FTP_BINARY);
     if ($result !== false) {
         rewind($tempHandle);
         return array('contents' => base64_encode(stream_get_contents($tempHandle)));
     } else {
         throw new Exception('Impossible d\'accéder au fichier "' . $file . '"');
     }
 }
Example #10
0
 public function _getFileContents($name)
 {
     $stream = fopen('php://temp', 'r+');
     if (@ftp_fget($this->getConnection(), $stream, $name, FTP_ASCII)) {
         rewind($stream);
         $contents = stream_get_contents($stream);
         fclose($stream);
         return $contents;
     } else {
         return false;
     }
 }
Example #11
0
 function _read($path)
 {
     $this->_chdir(dirname($path));
     $tmpFile = tmpfile();
     ftp_fget($this->_link, $tmpFile, basename($path), FTP_BINARY);
     $content = "";
     fseek($tmpFile, 0);
     while (!feof($tmpFile)) {
         $content = $content . fread($tmpFile, 4096);
     }
     fclose($tmpFile);
     return $content;
 }
 public function testAppend()
 {
     $appendFilePath = $this->workspace . DIRECTORY_SEPARATOR . 'append_source_file';
     $this->adapter->write($appendFilePath, 'foo', true);
     $temp = fopen('php://temp', 'r+');
     ftp_fget($this->connection, $temp, $appendFilePath, $this->mode);
     rewind($temp);
     $this->assertEquals('foo', stream_get_contents($temp));
     $this->adapter->write($appendFilePath, 'bar', true);
     rewind($temp);
     ftp_fget($this->connection, $temp, $appendFilePath, $this->mode);
     rewind($temp);
     $this->assertEquals('foobar', stream_get_contents($temp));
     fclose($temp);
 }
 public function getfile($filename)
 {
     if ($temp = $this->gettempfilehandle()) {
         fseek($temp, 0);
         ftruncate($temp, 0);
         if (@ftp_fget($this->handle, $temp, $filename, FTP_BINARY, $resumepos)) {
             fseek($temp, 0);
             $result = '';
             while (!feof($temp)) {
                 $result .= fread($temp, 8192);
             }
             return $result;
         }
     }
     return false;
 }
Example #14
0
 public function get($fn, $target = null)
 {
     if (is_string($target)) {
         if (!ftp_get($this->_ftpStream, $target, $fn, FTP_ASCII)) {
             $target = false;
         }
     } else {
         if (is_null($target)) {
             $target = tmpfile();
         }
         if (!ftp_fget($this->_ftpStream, $target, $fn, FTP_ASCII)) {
             $target = false;
         }
     }
     return $target;
 }
Example #15
0
 function Download($local_file, $remote_file)
 {
     //cria pasta temp caso não exista
     if (!file_exists(DOCUMENT_ROOT . NAME . '/ftp/temp')) {
         mkdir(DOCUMENT_ROOT . NAME . '/ftp/temp');
     }
     // open some file to write to
     $handle = fopen(DOCUMENT_ROOT . NAME . '/ftp' . $local_file, 'w');
     // try to download $remote_file and save it to $handle
     if (ftp_fget($this->Conn, $handle, $remote_file, FTP_ASCII, 0)) {
         echo "successfully written to {$local_file}\n";
         return true;
     } else {
         echo "There was a problem while downloading {$remote_file} to {$local_file}\n";
     }
 }
Example #16
0
function SaveComment($id, $comment)
{
    $temp = fopen('php://temp', 'r+');
    $ftp = GetFtpHandle();
    if ($ftp !== false) {
        ftp_fget($ftp, $temp, $id . ".comment", FTP_BINARY, 0);
        fwrite($temp, $comment . "\r\n");
        rewind($temp);
        if (ftp_fput($ftp, $id . ".comment", $temp, FTP_BINARY)) {
            fclose($temp);
            ftp_close($ftp);
            return true;
        }
        ftp_close($ftp);
    }
    fclose($temp);
    return false;
}
Example #17
0
 /**
  * public function get
  *
  *
  * @param    string $file
  * @return   string
  */
 public function get($file = '')
 {
     $tempHandle = fopen('php://temp', 'r+');
     $sizeFile = $this->size($file);
     if ($sizeFile > 512000) {
         // 512 000 KB
         return 'This file is too big to read, maximum filesize allowed to the browser: 512KB';
     } else {
         if (@ftp_fget($this->connection, $tempHandle, $file, FTP_ASCII, 0)) {
             rewind($tempHandle);
             $total = stream_get_contents($tempHandle);
             return $total;
         } else {
             return false;
         }
     }
     return false;
 }
Example #18
0
/**
 * @return String/FALSE on error
 * @param String $server
 * @param String $port
 * @param String $pasv
 * @param String $username
 * @param String $password
 * @param String $file
 * @desc Connects to an FTP server, requests the specified file, writes it to
 *       a temporary location and then loads it into a string.
 */
function open_from_ftp($server, $port = '', $pasv, $username, $password, $file)
{
    global $javascript_msg;
    // Set the port we're using
    $port = isset($port) && $port != '' ? $port : 0;
    // Connect to FTP Server
    if ($ftp = @ftp_connect($server, $port)) {
        // Log in using details provided
        if ($logged_in = @ftp_login($ftp, $username, $password)) {
            // Set PASV mode
            ftp_pasv($ftp, $pasv);
            // Create a temporary file, and get the remote file contents into it.
            $temp_file = 'temp/' . date('YmdHis') . '.wp';
            if ($local_file = @fopen($temp_file, 'wt')) {
                if (@ftp_fget($ftp, $local_file, $file, FTP_ASCII)) {
                    @ftp_quit($ftp);
                    fclose($local_file);
                    // Make sure that the file parsing function exists, or grab code for it
                    if (!function_exists('parse_file')) {
                        require_once 'common.php';
                    }
                    $string = parse_file($temp_file);
                    return $string;
                } else {
                    $javascript_msg = '@Could not get the file from the FTP Server.';
                    return false;
                }
            } else {
                $javascript_msg = '@Could not create temporary file. Check the permissions on webpad\'s temporary folder.';
                return false;
            }
        } else {
            $javascript_msg = '@Authentication failed on FTP Server \'' . $server . '\'.';
            return false;
        }
    } else {
        $javascript_msg = '@Could not connect to FTP Server \'' . $server . '\'.';
        return false;
    }
}
 /**
  * Opens the strem
  *
  * @param String $path Maybe in the form "ajxp.ftp://repositoryId/pathToFile" 
  * @param String $mode
  * @param unknown_type $options
  * @param unknown_type $opened_path
  * @return unknown
  */
 function stream_open($path, $mode, $options, &$opened_path)
 {
     $url = parse_url($path);
     $repoId = $url["host"];
     $repoObject = ConfService::getRepositoryById($repoId);
     if (!isset($repoObject)) {
         return false;
     }
     $this->repository = $repoObject;
     $this->user = $this->getUserName($repoObject);
     $this->password = $this->getPassword($repoObject);
     $res = $this->initRepository();
     $this->path = $this->secureFtpPath($this->path . "/" . $url["path"]);
     if ($mode == "r") {
         if ($contents = @ftp_rawlist($this->connect, $this->path) !== FALSE) {
             $this->cacheRHandler = tmpfile();
             @ftp_fget($this->connect, $this->cacheRHandler, $this->path, FTP_BINARY, 0);
             rewind($this->cacheRHandler);
         }
     }
     return true;
 }
 function get_contents($file, $type = '', $resumepos = 0)
 {
     if (empty($type)) {
         $extension = substr(strrchr($file, "."), 1);
         $type = isset($this->filetypes[$extension]) ? $this->filetypes[$extension] : FTP_ASCII;
     }
     $temp = tmpfile();
     if (!$temp) {
         return false;
     }
     if (!@ftp_fget($this->link, $temp, $file, $type, $resumepos)) {
         return false;
     }
     fseek($temp, 0);
     //Skip back to the start of the file being written to
     $contents = '';
     while (!feof($temp)) {
         $contents .= fread($temp, 8192);
     }
     fclose($temp);
     return $contents;
 }
Example #21
0
 function get_contents($file, $type = '', $resumepos = 0)
 {
     if (empty($type)) {
         $type = FTP_BINARY;
     }
     $tempfile = $this->create_tmp_file($file);
     $temp = fopen($tempfile, 'w+');
     if (!$temp) {
         return false;
     }
     if (!@ftp_fget($this->link, $temp, $file, $type, $resumepos)) {
         return false;
     }
     fseek($temp, 0);
     //Skip back to the start of the file being written to
     $contents = '';
     while (!feof($temp)) {
         $contents .= fread($temp, 8192);
     }
     fclose($temp);
     unlink($tempfile);
     return $contents;
 }
Example #22
0
 /**
  * Method to read a file from the FTP server's contents into a buffer
  *
  * @access public
  * @param string $remote Path to remote file to read on the FTP server
  * @param string $buffer Buffer variable to read file contents into
  * @return boolean True if successful
  */
 function read($remote, &$buffer)
 {
     // Determine file type
     $mode = $this->_findMode($remote);
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         // turn passive mode on
         if (@ftp_pasv($this->_conn, true) === false) {
             JError::raiseWarning('36', 'JFTP::read: Unable to use passive mode');
             return false;
         }
         $tmp = fopen('buffer://tmp', 'br+');
         if (@ftp_fget($this->_conn, $tmp, $remote, $mode) === false) {
             fclose($tmp);
             JError::raiseWarning('35', 'JFTP::read: Bad response');
             return false;
         }
         // Read tmp buffer contents
         rewind($tmp);
         $buffer = '';
         while (!feof($tmp)) {
             $buffer .= fread($tmp, 8192);
         }
         fclose($tmp);
         return true;
     }
     $this->_mode($mode);
     // Start passive mode
     if (!$this->_passive()) {
         JError::raiseWarning('36', 'JFTP::read: Unable to use passive mode');
         return false;
     }
     if (!$this->_putCmd('RETR ' . $remote, array(150, 125))) {
         @fclose($this->_dataconn);
         JError::raiseWarning('35', 'JFTP::read: Bad response', 'Server response: ' . $this->_response . ' [Expected: 150 or 125] Path sent: ' . $remote);
         return false;
     }
     // Read data from data port connection and add to the buffer
     $buffer = '';
     while (!feof($this->_dataconn)) {
         $buffer .= fread($this->_dataconn, 4096);
     }
     // Close the data port connection
     fclose($this->_dataconn);
     // Let's try to cleanup some line endings if it is ascii
     if ($mode == FTP_ASCII) {
         $buffer = preg_replace("/" . CRLF . "/", $this->_lineEndings[$this->_OS], $buffer);
     }
     if (!$this->_verifyResponse(226)) {
         JError::raiseWarning('37', 'JFTP::read: Transfer Failed', 'Server response: ' . $this->_response . ' [Expected: 226] Path sent: ' . $remote);
         return false;
     }
     return true;
 }
 /**
  * @param string $file
  * @return false|string
  */
 public function get_contents($file)
 {
     $tempfile = wp_tempnam($file);
     $temp = fopen($tempfile, 'w+');
     if (!$temp) {
         return false;
     }
     if (!@ftp_fget($this->link, $temp, $file, FTP_BINARY)) {
         return false;
     }
     fseek($temp, 0);
     // Skip back to the start of the file being written to
     $contents = '';
     while (!feof($temp)) {
         $contents .= fread($temp, 8192);
     }
     fclose($temp);
     unlink($tempfile);
     return $contents;
 }
Example #24
0
<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
ftp_login($ftp, 'user', 'pass');
if (!$ftp) {
    die("Couldn't connect to the server");
}
ftp_set_option($ftp, FTP_AUTOSEEK, false);
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_fget_basic1.txt";
$handle = fopen($local_file, 'w');
var_dump(ftp_fget($ftp, $handle, 'fget.txt', FTP_ASCII, FTP_AUTORESUME));
var_dump(file_get_contents($local_file));
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "ftp_fget_basic1.txt");
Example #25
0
 /**
  * Read a file to result, file or stream
  *
  * @param string $filename
  * @param string|resource|null $dest destination file name, stream, or if null will return file contents
  * @return string
  */
 public function read($filename, $dest = null)
 {
     if (is_string($dest)) {
         $result = ftp_get($this->_conn, $dest, $filename, $this->_config['file_mode']);
     } else {
         if (is_resource($dest)) {
             $stream = $dest;
         } elseif (is_null($dest)) {
             $stream = tmpfile();
         } else {
             $this->_error = self::ERROR_INVALID_DESTINATION;
             return false;
         }
         $result = ftp_fget($this->_conn, $stream, $filename, $this->_config['file_mode']);
         if (is_null($dest)) {
             fseek($stream, 0);
             $result = '';
             for ($result = ''; $s = fread($stream, 4096); $result .= $s) {
             }
             fclose($stream);
         }
     }
     return $result;
 }
Example #26
0
File: ftp.php Project: akksi/jcg
 /**
  * Method to read a file from the FTP server's contents into a buffer
  *
  * @access public
  * @param string $remote Path to remote file to read on the FTP server
  * @param string $buffer Buffer variable to read file contents into
  * @return boolean True if successful
  */
 function read($remote, &$buffer)
 {
     // Determine file type
     $mode = $this->_findMode($remote);
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         // turn passive mode on
         if (@ftp_pasv($this->_conn, true) === false) {
             JError::raiseWarning('36', JText::_('JLIB_CLIENT_ERROR_JFTP_READ_BAD_RESPONSE_PASSIVE'));
             return false;
         }
         $tmp = fopen('buffer://tmp', 'br+');
         if (@ftp_fget($this->_conn, $tmp, $remote, $mode) === false) {
             fclose($tmp);
             JError::raiseWarning('35', JText::_('JLIB_CLIENT_ERROR_JFTP_READ_BAD_RESPONSE_BUFFER'));
             return false;
         }
         // Read tmp buffer contents
         rewind($tmp);
         $buffer = '';
         while (!feof($tmp)) {
             $buffer .= fread($tmp, 8192);
         }
         fclose($tmp);
         return true;
     }
     $this->_mode($mode);
     // Start passive mode
     if (!$this->_passive()) {
         JError::raiseWarning('36', JText::_('JLIB_CLIENT_ERROR_JFTP_READ_BAD_RESPONSE_PASSIVE'));
         return false;
     }
     if (!$this->_putCmd('RETR ' . $remote, array(150, 125))) {
         @fclose($this->_dataconn);
         JError::raiseWarning('35', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_READ_BAD_RESPONSE', $this->_response, $remote));
         return false;
     }
     // Read data from data port connection and add to the buffer
     $buffer = '';
     while (!feof($this->_dataconn)) {
         $buffer .= fread($this->_dataconn, 4096);
     }
     // Close the data port connection
     fclose($this->_dataconn);
     // Let's try to cleanup some line endings if it is ascii
     if ($mode == FTP_ASCII) {
         $buffer = preg_replace("/" . CRLF . "/", $this->_lineEndings[$this->_OS], $buffer);
     }
     if (!$this->_verifyResponse(226)) {
         JError::raiseWarning('37', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_READ_BAD_RESPONSE_TRANSFER', $this->_response, $remote));
         return false;
     }
     return true;
 }
Example #27
0
$conn_id = ftp_connect($ftp_ip);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

/*
if ((!$conn_id) || (!$login_result)) {
echo "<font color=\"#FF0000\">Could not retrieve ban list.</font>";
exit;
} else {
echo "<font color=\"#00FF00\">Retrieved ban list successfully.</font>\n";
echo "<br />\n";
echo "<br />\n";
}*/

// get the file
$local = fopen($temporary_file, "w");
$result = ftp_fget($conn_id, $local, $ftp_log_path, FTP_ASCII);

// close the FTP stream
ftp_close($conn_id);


$myFile = $temporary_file;
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);

echo '<h1 style="color:#fff;margin:0px;padding:0px;font-size:50px;">mdb Ban lista</h1>';
echo "<table border=\"0\" cellpadding=\"3\" style=\"width: 100%;\">\n";
echo "<tr>\n";
echo "<td style=\"background-color: #333333; color: #FFFFFF; font-size: small;\">Igrac:</td>\n";
echo "<td style=\"background-color: #333333; color: #FFFFFF; font-size: small;\">Steam,Valve ili IP:</td>\n";
Example #28
0
 /**
  * @inheritdoc
  */
 public function readStream($path)
 {
     $stream = fopen('php://temp', 'w+');
     $result = ftp_fget($this->getConnection(), $stream, $path, $this->transferMode);
     rewind($stream);
     if (!$result) {
         fclose($stream);
         return false;
     }
     return compact('stream');
 }
 /**
  * Open file and return file pointer
  *
  * @param  string $path file path
  * @param string $mode
  * @return false|resource
  * @internal param bool $write open file for writing
  * @author Dmitry (dio) Levashov
  */
 protected function _fopen($path, $mode = 'rb')
 {
     // try ftp stream wrapper
     if ($this->options['mode'] == 'passive' && ini_get('allow_url_fopen')) {
         $url = 'ftp://' . $this->options['user'] . ':' . $this->options['pass'] . '@' . $this->options['host'] . ':' . $this->options['port'] . $path;
         if (strtolower($mode[0]) === 'w') {
             $context = stream_context_create(array('ftp' => array('overwrite' => true)));
             $fp = @fopen($url, $mode, false, $context);
         } else {
             $fp = @fopen($url, $mode);
         }
         if ($fp) {
             return $fp;
         }
     }
     if ($this->tmp) {
         $local = $this->getTempFile($path);
         $fp = @fopen($local, 'wb');
         if (ftp_fget($this->connect, $fp, $path, FTP_BINARY)) {
             fclose($fp);
             $fp = fopen($local, $mode);
             return $fp;
         }
         @fclose($fp);
         is_file($local) && @unlink($local);
     }
     return false;
 }
Example #30
0
 /** Gets a file from the server.
  * This function gets the contents of a file from the server, with the protocole set to read the log (so it also works on remote servers).
  * 
  * \param $file File name.
  * 
  * \return A string containing the file's contents, or FALSE if an error happened.
  */
 public function fileGetContents($file)
 {
     switch ($this->_logfile['type']) {
         case 'file':
             return file_get_contents($file);
             break;
         case 'ftp':
             $buffer = fopen('php://memory', 'r+');
             if (!ftp_fget($this->_logfile['ftp'], $buffer, $file, FTP_BINARY)) {
                 return FALSE;
             }
             fseek($buffer, 0);
             $str = '';
             while (!feof($buffer)) {
                 $str .= fgets($buffer);
             }
             fclose($buffer);
             return $str;
             break;
     }
 }