public function writeFile($local, $remote, callable $progress = NULL)
{
$size = max(filesize($local), 1);
$retry = self::RETRIES;
upload:
$blocks = 0;
do {
if ($progress) {
$progress(min($blocks * self::BLOCK_SIZE / $size, 100));
}
try {
$ret = $blocks === 0 ? $this->ftp('nb_put', $remote, $local, FTP_BINARY) : $this->ftp('nb_continue');
} catch (FtpException $e) {
@ftp_close($this->connection);
// intentionally @
$this->connect();
if (--$retry) {
goto upload;
}
throw new FtpException("Cannot upload file {$local}, number of retries exceeded. Error: {$e->getMessage()}");
}
$blocks++;
} while ($ret === FTP_MOREDATA);
if ($progress) {
$progress(100);
}
}