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 for the isDir function in the FTP Adapter #607

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
28 changes: 27 additions & 1 deletion src/Gaufrette/Adapter/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ protected function createDirectory($directory)
}
}

/**
* @return string
*/
private function createConnectionUrl() {
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
$url = $this->ssl ? 'sftp://' : 'ftp://';
Romain marked this conversation as resolved.
Show resolved Hide resolved
$url .= $this->username . ':' . $this->password . '@' . $this->host;
$url .= $this->port ? ':' . $this->port : '';

return $url;
}

/**
* @param string $directory - full directory path
*
Expand All @@ -366,7 +377,22 @@ private function isDir($directory)
return true;
}

if (!@ftp_chdir($this->getConnection(), $directory)) {
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
$chDirResult = false;
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
try {
$chDirResult = ftp_chdir($this->getConnection(), $directory);
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
}
catch(Exception $e) {
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
$this->passive = true;
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved

nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
// Build the FTP URL that will be used to check if the path is a directory or not
$url = $this->createConnectionUrl();
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved

if (!@is_dir($url . $directory)) {
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
}

if (!$chDirResult) {
nicolasmure marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

Expand Down