/** * Downloads a file to $this->localDir * * @author Art <*****@*****.**> * @see self::$localDir * * @param string $file Remote file name * * @throws SE When the file cannot be fetched * @throws FE When the name is invalid * @return SFTP */ function downloadFile($file) { \Log::debug('Downloading file ' . $file . ' to ' . $this->localDir); $fetch = $this->getFileContents($file); $local = new File(); $local->dir($this->localDir)->name($file); $local->content($fetch)->write(); return $this; }
/** * The progress function * * @author Art <*****@*****.**> * * @param resource $resource Coulsn't find documentation on this one, most likely the curl resource * @param int $downloadSize How much we are downloading * @param int $downloaded How much we have downloaded * @param int $uploadSize How much we are uploading * @param int $uploaded How much we have uploaded */ function progressFunction($resource, $downloadSize, $downloaded, $uploadSize, $uploaded) { $ed = $size = 0; if ($downloadSize > 0 && $downloaded > 0) { $ed = $downloaded; $size = $downloadSize; } elseif ($uploadSize > 0 && $uploaded > 0) { $ed = $uploaded; $size = $uploadSize; } if ($ed && $size && $this->reportCount++ != 0) { $status = File::convertSize($ed) . '/' . File::convertSize($size) . ' downloaded [' . round($ed / $size * 100, 3) . ' %]'; $time = time(); if ($status != $this->lastReportStatus && ($time != $this->lastReportTime || $ed == $size)) { $this->lastReportTime = $time; $this->lastReportStatus = $status; echo $status . PHP_EOL; } $this->reportCount++; } //Unnecessary, but stops the IDE from thinking the variable is unused unset($resource); }