Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in detecting file name (when there are two spaces in filename) #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Touki/FTP/FTPWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function setConnection(ConnectionInterface $connection)
*/
public function get($localFile, $remoteFile, $mode = self::BINARY, $resumepos = 0)
{
return ftp_get($this->connection->getStream(), $localFile, $remoteFile, $mode, $resumepos);
try{
return ftp_get($this->connection->getStream(), $localFile, $remoteFile, $mode, $resumepos);
}catch (\Exception $e){
return ftp_get($this->connection->getStream(), $localFile, str_replace(' ', '\\ ', $remoteFile), $mode, $resumepos);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lib/Touki/FTP/FilesystemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public function build($input, $prefix = '')
$filesystem = $this->resolveFile($type);
$permParts = str_split(substr($parts[0], 1, 9), 3);
$hours = sscanf($parts[7], "%d:%d");
$name = implode(' ', array_slice($parts, 8));

$nameStart = strpos($input, $parts[7]);
$nameStart += strlen($parts[7]) + 1;
$name = trim(substr($input, $nameStart));

if (null === $hours[1]) {
$year = $hours[0];
Expand Down
11 changes: 11 additions & 0 deletions lib/Touki/FTP/Manager/FTPFilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ public function findBy($directory, $callable)
}

$directory = '/'.ltrim($directory, '/');

$raw = $this->wrapper->rawlist($directory);
$list = array();

if (false === $raw) {
throw new DirectoryException(sprintf("Directory %s not found", $directory));
}

if(is_array($raw) && empty($raw)){
$raw = $this->wrapper->rawlist(str_replace(' ', '\\ ', $directory));
}

foreach ($raw as $item) {
$fs = $this->factory->build($item, $directory);

Expand Down Expand Up @@ -158,6 +163,11 @@ public function findOneBy($directory, $callable)
throw new DirectoryException(sprintf("Directory %s not found", $directory));
}

if(is_array($raw) && empty($raw)){
$raw = $this->wrapper->rawlist(str_replace(' ', '\\ ', $directory));
}


foreach ($raw as $item) {
$fs = $this->factory->build($item, $directory);

Expand All @@ -170,6 +180,7 @@ public function findOneBy($directory, $callable)
}
}


return null;
}

Expand Down