diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index b15add8dc..73a53bc69 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -592,12 +592,14 @@ private function ensureDirectoryExists(string $dirname, ?string $visibility): vo $dirPath = ''; $parts = explode('/', trim($dirname, '/')); $mode = $visibility ? $this->visibilityConverter->forDirectory($visibility) : false; + $original_directory = @ftp_pwd($connection); foreach ($parts as $part) { $dirPath .= '/' . $part; $location = $this->prefixer()->prefixPath($dirPath); if (@ftp_chdir($connection, $location)) { + @ftp_chdir($connection, $original_directory); continue; }