public static function init($youtube_video_url, $final_flv_filename, $test = 0, $overwrite = 0){
        self::$youtube_video_url = $youtube_video_url;
        self::$test = $test;
        self::$final_flv_filename = $final_flv_filename;
        
        self::$youtube_video_id = self::get_youtube_video_id();
        
        self::$cookies_path = "cookies.txt";
        $clear_cookies = self::clear_cookies();
        
        self::$curl_headers = Array(
        	"Accept-Language: en-us",
        	"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15",
        	"Connection: Keep-Alive",
        	"Cache-Control: no-cache"
        );
        self::$flv_url = self::get_flv_url();
        
		$fs = OCP\Files::getStorage('files');
		if($fs->file_exists('/Downloads/' . $final_flv_filename) && !$overwrite){
			self::$final_flv_filename = md5(rand()) . '_' . $final_flv_filename;
		}
		self::$fs = $fs->fopen('/Downloads/' . self::$final_flv_filename, 'w');
		
        $save_binary = self::get_curl_binary();
        $clear_cookies = self::clear_cookies();
    
    }
Ejemplo n.º 2
0
 public function fopen($path, $mode)
 {
     switch ($mode) {
         case 'r':
         case 'rb':
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
             //these are supported by the wrapper
             $context = stream_context_create(array('ftp' => array('overwrite' => true)));
             return fopen($this->constructUrl($path), $mode, false, $context);
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             //emulate these
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = OCP\Files::tmpFile($ext);
             OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
             if ($this->file_exists($path)) {
                 $this->getFile($path, $tmpFile);
             }
             self::$tempFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 3
0
 public static function getThumbnail($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $view = OCP\Files::getStorage('gallery');
     $save_dir = dirname($image_name);
     if (!$view->is_dir($save_dir)) {
         $view->mkdir($save_dir);
     }
     $view->chroot($view->getRoot() . '/' . $save_dir);
     $thumb_file = basename($image_name);
     if ($view->file_exists($thumb_file)) {
         $image = new OC_Image($view->fopen($thumb_file, 'r'));
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_name);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->centerCrop(200);
             $image->fixOrientation();
             $image->save($view->getLocalFile($thumb_file));
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
Ejemplo n.º 4
0
function handleGetThumbnails($albumname)
{
    OCP\Response::enableCaching(3600 * 24);
    // 24 hour
    $view = OCP\Files::getStorage('gallery');
    $thumbnail = $view->fopen(urldecode($albumname) . '.png', 'r');
    header('Content-Type: ' . OC_Image::getMimeTypeForFile($thumbnail));
    OCP\Response::sendFile($thumbnail);
}
	/**
	 * Get the file by an URL
	 * @param $url URL of the file
	 * @param $path Simple path of the file
	 * @param $l Lang
	 * @param $overwrite Overwrite the target file
	 */
	public static function getFile($url, $path, $l, $overwrite = 0){
		try{
			$code = 0;
			if(!self::checkFileAccess($url, $code)){
				OC_ocDownloaderPB::setError($l->t(self::$errors[$code]));
				exit();
			}
			
			$pathinfo = pathinfo($path);
			$fs = OCP\Files::getStorage('files');
			if($fs->file_exists('/Downloads/' . $pathinfo['basename']) && !$overwrite){
				$pathinfo['basename'] = md5(rand()) . '_' . $pathinfo['basename'];
			}
			$fs = $fs->fopen('/Downloads/' . $pathinfo['basename'], 'w');
			
			$size = self::getRemoteFileSize($url);
			if($size == 0){
				OC_ocDownloaderPB::setError($l->t('Filesize is null'));
				exit();
			}
			$chunkSize = self::getChunkSize($size);
		
		    $fp = fopen($url, 'rb');
			$received = $last = 0;
			
		    while(!feof($fp)){
		        $data = @fread($fp, $chunkSize);
		        if($data == ''){
		        	break;
		        }
				$saved = fwrite($fs, $data);
				if($saved > -1){
					$received += $saved;
				}
				if($received >= $size){
	                $percent = 100;
	            }else{
	                $percent = @round(($received/$size)*100, 2);
	            }
				if($received > $last + $chunkSize){
					OC_ocDownloaderPB::setProgressBarProgress($percent);
					$last = $received;
				}
				usleep(100);
		    }
			OC_ocDownloaderPB::setProgressBarProgress(100);
			OC_ocDownloader::setUserHistory($pathinfo['basename'], 1);
		
		    fclose($fp);fclose($fs);
		}catch(exception $e){
			OC_ocDownloaderPB::setError($l->t('Unknown error'));
		}
	}
Ejemplo n.º 6
0
 /**
  * get a cryptstream to a temporary file
  * @param string $id
  * @param string $mode
  * @return resource
  */
 function getStream($id, $mode)
 {
     if ($id === '') {
         $id = uniqid();
     }
     if (!isset($this->tmpFiles[$id])) {
         $file = OCP\Files::tmpFile();
         $this->tmpFiles[$id] = $file;
     } else {
         $file = $this->tmpFiles[$id];
     }
     $stream = fopen($file, $mode);
     OC_CryptStream::$sourceStreams[$id] = array('path' => 'dummy', 'stream' => $stream);
     return fopen('crypt://streams/' . $id, $mode);
 }
Ejemplo n.º 7
0
 public static function createThumbnails($albumName, $files)
 {
     // create gallery thumbnail
     $file_count = min(count($files), 10);
     $thumbnail = imagecreatetruecolor($file_count * 200, 200);
     for ($i = 0; $i < $file_count; $i++) {
         $image = OC_Gallery_Photo::getThumbnail($files[$i]);
         if ($image && $image->valid()) {
             imagecopyresampled($thumbnail, $image->resource(), $i * 200, 0, 0, 0, 200, 200, 200, 200);
             $image->destroy();
         }
     }
     $view = OCP\Files::getStorage('gallery');
     imagepng($thumbnail, $view->getLocalFile($albumName . '.png'));
     imagedestroy($thumbnail);
 }
Ejemplo n.º 8
0
 function testEncryption()
 {
     $key = uniqid();
     $file = OC::$SERVERROOT . '/3rdparty/MDB2.php';
     $source = file_get_contents($file);
     //nice large text file
     $encrypted = OC_Crypt::encrypt($source, $key);
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $decrypted = rtrim($decrypted, "");
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $chunk = substr($source, 0, 8192);
     $encrypted = OC_Crypt::encrypt($chunk, $key);
     $this->assertEqual(strlen($chunk), strlen($encrypted));
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $decrypted = rtrim($decrypted, "");
     $this->assertEqual($decrypted, $chunk);
     $encrypted = OC_Crypt::blockEncrypt($source, $key);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $tmpFileEncrypted = OCP\Files::tmpFile();
     OC_Crypt::encryptfile($file, $tmpFileEncrypted, $key);
     $encrypted = file_get_contents($tmpFileEncrypted);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertNotEqual($encrypted, $source);
     $this->assertEqual($decrypted, $source);
     $tmpFileDecrypted = OCP\Files::tmpFile();
     OC_Crypt::decryptfile($tmpFileEncrypted, $tmpFileDecrypted, $key);
     $decrypted = file_get_contents($tmpFileDecrypted);
     $this->assertEqual($decrypted, $source);
     $file = OC::$SERVERROOT . '/core/img/weather-clear.png';
     $source = file_get_contents($file);
     //binary file
     $encrypted = OC_Crypt::encrypt($source, $key);
     $decrypted = OC_Crypt::decrypt($encrypted, $key);
     $decrypted = rtrim($decrypted, "");
     $this->assertEqual($decrypted, $source);
     $encrypted = OC_Crypt::blockEncrypt($source, $key);
     $decrypted = OC_Crypt::blockDecrypt($encrypted, $key);
     $this->assertEqual($decrypted, $source);
 }
Ejemplo n.º 9
0
 private function getTmpFile($path)
 {
     $obj = $this->getObject($path);
     if (!is_null($obj)) {
         $tmpFile = OCP\Files::tmpFile();
         $obj->save_to_filename($tmpFile);
         return $tmpFile;
     } else {
         return false;
     }
 }
Ejemplo n.º 10
0
Archivo: tar.php Proyecto: Romua1d/core
 protected function getNew()
 {
     return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
 }
Ejemplo n.º 11
0
 public function touch($path, $mtime = null)
 {
     if (is_null($mtime)) {
         $tmpFile = OCP\Files::tmpFile();
         $this->archive->extractFile($path, $tmpFile);
         $this->archive->addfile($path, $tmpFile);
     } else {
         return false;
         //not supported
     }
 }
Ejemplo n.º 12
0
 public function setUp()
 {
     $this->tmpFile = OCP\Files::tmpFile('.tar.gz');
     $this->instance = new OC_Filestorage_Archive(array('archive' => $this->tmpFile));
 }
Ejemplo n.º 13
0
 public function testExtract()
 {
     $dir = OC::$SERVERROOT . '/tests/data';
     $this->instance = $this->getExisting();
     $tmpDir = OCP\Files::tmpFolder();
     $this->instance->extract($tmpDir);
     $this->assertEquals(true, file_exists($tmpDir . 'lorem.txt'));
     $this->assertEquals(true, file_exists($tmpDir . 'dir/lorem.txt'));
     $this->assertEquals(true, file_exists($tmpDir . 'logo-wide.png'));
     $this->assertEquals(file_get_contents($dir . '/lorem.txt'), file_get_contents($tmpDir . 'lorem.txt'));
     OCP\Files::rmdirr($tmpDir);
 }
Ejemplo n.º 14
0
 protected function getNew()
 {
     return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
 }
Ejemplo n.º 15
0
 $fileCount = count($files['name']);
 for ($i = 0; $i < $fileCount; $i++) {
     if (isset($_POST['resolution'])) {
         $resolution = $_POST['resolution'];
     } else {
         $resolution = null;
     }
     // target directory for when uploading folders
     $relativePath = '';
     if (!empty($_POST['file_directory'])) {
         $relativePath = '/' . $_POST['file_directory'];
     }
     // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
     if ($resolution === 'autorename') {
         // append a number in brackets like 'filename (2).ext'
         $target = OCP\Files::buildNotExistingFileName($dir . $relativePath, $files['name'][$i]);
     } else {
         $target = \OC\Files\Filesystem::normalizePath($dir . $relativePath . '/' . $files['name'][$i]);
     }
     // relative dir to return to the client
     if (isset($publicDirectory)) {
         // path relative to the public root
         $returnedDir = $publicDirectory . $relativePath;
     } else {
         // full path
         $returnedDir = $dir . $relativePath;
     }
     $returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
     $exists = \OC\Files\Filesystem::file_exists($target);
     if ($exists) {
         $updatable = \OC\Files\Filesystem::isUpdatable($target);
Ejemplo n.º 16
0
    OCP\JSON::error(array('data' => array('message' => $l->t('Not enough storage available'), 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize)));
    exit;
}
$result = array();
if (strpos($dir, '..') === false) {
    $fileCount = count($files['name']);
    for ($i = 0; $i < $fileCount; $i++) {
        // target directory for when uploading folders
        $relativePath = '';
        if (!empty($_POST['file_directory'])) {
            $relativePath = '/' . $_POST['file_directory'];
        }
        // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
        if (isset($_POST['resolution']) && $_POST['resolution'] === 'autorename') {
            // append a number in brackets like 'filename (2).ext'
            $target = OCP\Files::buildNotExistingFileName(stripslashes($dir . $relativePath), $files['name'][$i]);
        } else {
            $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir . $relativePath) . '/' . $files['name'][$i]);
        }
        // relative dir to return to the client
        if (isset($publicDirectory)) {
            // path relative to the public root
            $returnedDir = $publicDirectory . $relativePath;
        } else {
            // full path
            $returnedDir = $dir . $relativePath;
        }
        $returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
        if (!\OC\Files\Filesystem::file_exists($target) || isset($_POST['resolution']) && $_POST['resolution'] === 'replace') {
            // upload and overwrite file
            try {
Ejemplo n.º 17
0
 public function fopen($path, $mode)
 {
     $path = $this->cleanPath($path);
     switch ($mode) {
         case 'r':
         case 'rb':
             //straight up curl instead of sabredav here, sabredav put's the entire get result in memory
             $curl = curl_init();
             $fp = fopen('php://temp', 'r+');
             curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password);
             curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . $path);
             curl_setopt($curl, CURLOPT_FILE, $fp);
             curl_exec($curl);
             curl_close($curl);
             rewind($fp);
             return $fp;
         case 'w':
         case 'wb':
         case 'a':
         case 'ab':
         case 'r+':
         case 'w+':
         case 'wb+':
         case 'a+':
         case 'x':
         case 'x+':
         case 'c':
         case 'c+':
             //emulate these
             if (strrpos($path, '.') !== false) {
                 $ext = substr($path, strrpos($path, '.'));
             } else {
                 $ext = '';
             }
             $tmpFile = OCP\Files::tmpFile($ext);
             OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
             if ($this->file_exists($path)) {
                 $this->getFile($path, $tmpFile);
             }
             self::$tempFiles[$tmpFile] = $path;
             return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 18
0
 /**
  * get a file handler
  *
  * @param string $path
  * @param string $mode
  * @return resource
  */
 function getStream($path, $mode)
 {
     if (strrpos($path, '.') !== false) {
         $ext = substr($path, strrpos($path, '.'));
     } else {
         $ext = '';
     }
     $tmpFile = OCP\Files::tmpFile($ext);
     if ($this->fileExists($path)) {
         $this->extractFile($path, $tmpFile);
     } elseif ($mode == 'r' or $mode == 'rb') {
         return false;
     }
     if ($mode == 'r' or $mode == 'rb') {
         return fopen($tmpFile, $mode);
     } else {
         \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
         self::$tempFiles[$tmpFile] = $path;
         return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 19
0
function handleGetPhoto($token, $photo)
{
    $owner = OC_Gallery_Sharing::getTokenOwner($token);
    $view = OCP\Files::getStorage('files');
    $file = $view->fopen(urldecode($photo), 'r');
    header('Content-Type: ' . OC_Image::getMimeTypeForFile($file));
    OCP\Response::sendFile($file);
}
Ejemplo n.º 20
0
 public static function changeThumbnailPath($oldname, $newname)
 {
     $view = OCP\Files::getStorage('gallery');
     $view->rename($oldname . '.png', $newname . '.png');
 }
Ejemplo n.º 21
0
<?php

//update from OC 3
//try to remove remaining files.
//Give a warning if not possible
$filesToRemove = array('ajax', 'appinfo', 'css', 'js', 'l10n', 'templates', 'admin.php', 'download.php', 'index.php', 'settings.php');
foreach ($filesToRemove as $file) {
    $filepath = OC::$SERVERROOT . '/files/' . $file;
    if (!file_exists($filepath)) {
        continue;
    }
    $success = OCP\Files::rmdirr($filepath);
    if ($success === false) {
        //probably not sufficient privileges, give up and give a message.
        OCP\Util::writeLog('files', 'Could not clean /files/ directory. Please remove everything except webdav.php from ' . OC::$SERVERROOT . '/files/', OCP\Util::ERROR);
        break;
    }
}
Ejemplo n.º 22
0
 public function postGetMimeType($path, $mime)
 {
     if (self::isEncrypted($path)) {
         $mime = OCP\Files::getMimeType('crypt://' . $path, 'w');
     }
     return $mime;
 }
Ejemplo n.º 23
0
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
OCP\App::checkAppEnabled('storagecharts2');
$l = new OC_L10N('storagecharts2');
OC::$CLASSPATH['OC_DLStCharts'] = OC_App::getAppPath('storagecharts2') . "/lib/db.class.php";
OC::$CLASSPATH['OC_DLStChartsLoader'] = OC_App::getAppPath('storagecharts2') . "/lib/loader.class.php";
OCP\App::addNavigationEntry(array('id' => 'storagecharts2_index', 'order' => 60, 'href' => OCP\Util::linkTo('storagecharts2', 'index.php'), 'icon' => OCP\Util::imagePath('storagecharts2', 'app.svg'), 'name' => $l->t('Usage')));
OCP\App::registerPersonal('storagecharts2', 'settings');
// Get storage value for logged in user
$data_dir = OCP\Config::getSystemValue('datadirectory', '');
if (OCP\User::getUser() && strlen($data_dir) != 0) {
    $fs = OCP\Files::getStorage('files');
    // workaround to detect OC version
    $ocVersion = @reset(OCP\Util::getVersion());
    // OC 5
    if ($ocVersion < 6) {
        OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud 5', OCP\Util::DEBUG);
        $used = OC_DLStCharts::getTotalDataSize(OC::$CONFIG_DATADIRECTORY);
        // OC 6 or greater
    } else {
        $datadir = OC_Config::getValue('datadirectory') . '/' . OCP\User::getUser();
        OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud ' . $ocVersion, OCP\Util::DEBUG);
        $used = OC_DLStCharts::getTotalDataSize($datadir);
    }
    // omit errors in desktop client ...
    if (method_exists($fs, 'free_space')) {
        OCP\Util::writeLog('storagecharts2', 'Calculating available space in oc << 8 for client', OCP\Util::DEBUG);
Ejemplo n.º 24
0
 /**
  * get a file handler
  * @param string path
  * @param string mode
  * @return resource
  */
 function getStream($path, $mode)
 {
     if ($mode == 'r' or $mode == 'rb') {
         return $this->zip->getStream($path);
     } else {
         //since we cant directly get a writable stream,
         //make a temp copy of the file and put it back
         //in the archive when the stream is closed
         if (strrpos($path, '.') !== false) {
             $ext = substr($path, strrpos($path, '.'));
         } else {
             $ext = '';
         }
         $tmpFile = OCP\Files::tmpFile($ext);
         OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
         if ($this->fileExists($path)) {
             $this->extractFile($path, $tmpFile);
         }
         self::$tempFiles[$tmpFile] = $path;
         return fopen('close://' . $tmpFile, $mode);
     }
 }
Ejemplo n.º 25
0
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/uploadimport.php: ' . $msg, OCP\Util::ERROR);
    exit;
}
$view = OCP\Files::getStorage('contacts');
$tmpfile = md5(rand());
// If it is a Drag'n'Drop transfer it's handled here.
$fn = isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false;
if ($fn) {
    if ($view->file_put_contents('/' . $tmpfile, file_get_contents('php://input'))) {
        OCP\JSON::success(array('data' => array('path' => '', 'file' => $tmpfile)));
        exit;
    } else {
        bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
    }
}
// File input transfers are handled here
if (!isset($_FILES['importfile'])) {
    OCP\Util::writeLog('contacts', 'ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
    OCP\JSON::error(array('data' => array('message' => 'No file was uploaded. Unknown error')));
Ejemplo n.º 26
0
if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
    exit;
}
$token = $_POST['token'];
$remote = $_POST['remote'];
$owner = $_POST['owner'];
$name = $_POST['name'];
$password = $_POST['password'];
// Check for invalid name
if (!\OCP\Util::isValidFileName($name)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.'))));
    exit;
}
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession());
$name = OCP\Files::buildNotExistingFileName('/', $name);
// check for ssl cert
if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t("Invalid or untrusted SSL certificate"))));
    exit;
} else {
    $mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
    /**
     * @var \OCA\Files_Sharing\External\Storage $storage
     */
    $storage = $mount->getStorage();
    $result = $storage->file_exists('');
    if ($result) {
        $storage->getScanner()->scanAll();
        \OCP\JSON::success();
    } else {
Ejemplo n.º 27
0
 public function tearDown()
 {
     if ($this->instance) {
         OCP\Files::rmdirr($this->instance->constructUrl(''));
     }
 }
	/**
	 * Get file
	 * @param $path The remote file path
	 * @param $l Lang
	 * @param $overwrite Overwrite the target file
	 */
	public static function getFile($path, $l, $overwrite){
		try{
			$pathinfo = pathinfo($path);
			$fs = OCP\Files::getStorage('files');
			if($fs->file_exists('/Downloads/' . $pathinfo['basename']) && !$overwrite){
				$pathinfo['basename'] = md5(rand()) . '_' . $pathinfo['basename'];
			}
			
			$size = self::getRemoteFileSize($path);
			if($size == 0){
				OC_ocDownloaderPB::setError($l->t('Filesize is null'));
				self::closeConnection();
				exit();
			}
			$chunkSize = self::getChunkSize($size);
			
			$received = $last = 0;
			$ret = ftp_nb_get(self::$conn, $fs->getLocalFile('/Downloads/' . $pathinfo['basename']), $path, FTP_BINARY);
			while($ret == FTP_MOREDATA){
				$received += $fs->filesize('/Downloads/' . $pathinfo['basename']);
				if($received >= $size){
	                $percent = 100;
	            }else{
	                $percent = @round(($received/$size)*100, 2);
	            }
				
				if($received > $last + $chunkSize){
					OC_ocDownloaderPB::setProgressBarProgress($percent);
					$last = $received;
				}
				
				usleep(100);
			   	$ret = ftp_nb_continue(self::$conn);
			}
			if($ret != FTP_FINISHED){
			   	OC_ocDownloaderPB::setError($l->t('Download error'));
				self::closeConnection();
			   	exit();
			}else{
				OC_ocDownloaderPB::setProgressBarProgress(100);
				OC_ocDownloader::setUserHistory($pathinfo['basename'], 1);
			}
			
			self::closeConnection();
		}catch(exception $e){
			OC_ocDownloaderPB::setError($l->t('Unknown error'));
		}
	}