本文整理汇总了PHP中ftp_fget函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_fget函数的具体用法?PHP ftp_fget怎么用?PHP ftp_fget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_fget函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
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);
}
示例2: fetchFile
/**
* 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;
}
示例3: copyFileInStream
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);
}
示例4: ftpGetContents
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);
}
示例5: ftp_get_string
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.";
}
}
示例6: read
/**
* {@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;
}
示例7: read
/**
* {@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;
}
示例8: executeGetFileAsBinary
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 . '"');
}
}
示例9: getFileAsBinary
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 . '"');
}
}
示例10: _getFileContents
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;
}
}
示例11: _read
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;
}
示例12: testAppend
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);
}
示例13: getfile
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;
}
示例14: get
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;
}
示例15: Download
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";
}
}