Skip to content

Commit

Permalink
fix ftp external storage with filezilla server
Browse files Browse the repository at this point in the history
- filezilla doesn't like "" as parameter for `mdtm` (all others seem fine)
- filezilla sends fractional modified date

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 30, 2023
1 parent 636c241 commit fd0ef58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 7 additions & 5 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public function filemtime($path) {
return $item['type'] === 'cdir';
}));
if ($currentDir) {
$time = \DateTime::createFromFormat('YmdHis', $currentDir['modify'] ?? '');
[$modify] = explode('.', $currentDir['modify'] ?? '', 2);
$time = \DateTime::createFromFormat('YmdHis', $modify);
if ($time === false) {
throw new \Exception("Invalid date format for directory: $currentDir");
}
Expand Down Expand Up @@ -355,10 +356,11 @@ public function getDirectoryContent($directory): \Traversable {

$data = [];
$data['mimetype'] = $isDir ? FileInfo::MIMETYPE_FOLDER : $mimeTypeDetector->detectPath($name);
$data['mtime'] = \DateTime::createFromFormat('YmdGis', $file['modify'])->getTimestamp();
if ($data['mtime'] === false) {
$data['mtime'] = time();
}

// strip fractional seconds
[$modify] = explode('.', $file['modify'], 2);
$mtime = \DateTime::createFromFormat('YmdGis', $modify);
$data['mtime'] = $mtime === false ? time() : $mtime->getTimestamp();
if ($isDir) {
$data['size'] = -1; //unknown
} elseif (isset($file['size'])) {
Expand Down
10 changes: 8 additions & 2 deletions apps/files_external/lib/Lib/Storage/FtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ public function rename(string $source, string $target) {
return @ftp_rename($this->connection, $source, $target);
}

public function mdtm(string $path) {
return @ftp_mdtm($this->connection, $path);
public function mdtm(string $path): int {
$result = @ftp_mdtm($this->connection, $path);

// filezilla doesn't like empty path with mdtm
if ($result === -1 && $path === "") {
$result = @ftp_mdtm($this->connection, "/");
}
return $result;
}

public function size(string $path) {
Expand Down

0 comments on commit fd0ef58

Please sign in to comment.