Index: wp-admin/includes/class-wp-filesystem-direct.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-direct.php	(revision 10008)
+++ wp-admin/includes/class-wp-filesystem-direct.php	(working copy)
@@ -104,7 +104,7 @@
 		return $ownerarray['name'];
 	}
 	function getchmod($file) {
-		return @fileperms($file);
+		return substr(decoct(@fileperms($file)),3);
 	}
 	function group($file) {
 		$gid = @filegroup($file);
Index: wp-admin/includes/class-wp-filesystem-ftpext.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-ftpext.php	(revision 10008)
+++ wp-admin/includes/class-wp-filesystem-ftpext.php	(working copy)
@@ -169,7 +169,7 @@
 	}
 	function getchmod($file) {
 		$dir = $this->dirlist($file);
-		return $dir[$file]['permsn'];
+		return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
 	}
 	function group($file) {
 		$dir = $this->dirlist($file);
@@ -321,11 +321,12 @@
 	}
 
 	function dirlist($path = '.', $incdot = false, $recursive = false) {
-		if( $this->is_file($path) ) {
-			$limitFile = basename($path);
-			$path = dirname($path) . '/';
+
+		if ( substr($path, -1) !== '/') {
+			$limit = basename($path);
+			$path = trailingslashit(dirname($path));
 		} else {
-			$limitFile = false;
+			$limit = false;
 		}
 
 		$list = @ftp_rawlist($this->link, '-a ' . $path, false);
@@ -339,9 +340,12 @@
 			if ( empty($entry) )
 				continue;
 
-			if ( '.' == $entry["name"] || '..' == $entry["name"] )
+			if ( '.' == $entry['name'] || '..' == $entry['name'] )
 				continue;
 
+			if ( $limit && $entry['name'] != $limit )
+				continue;
+
 			$dirlist[ $entry['name'] ] = $entry;
 		}
 
Index: wp-admin/includes/class-wp-filesystem-ftpsockets.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-ftpsockets.php	(revision 10008)
+++ wp-admin/includes/class-wp-filesystem-ftpsockets.php	(working copy)
@@ -186,7 +186,7 @@
 
 	function getchmod($file) {
 		$dir = $this->dirlist($file);
-		return $dir[$file]['permsn'];
+		return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
 	}
 
 	function group($file) {
@@ -281,21 +281,25 @@
 	}
 
 	function dirlist($path = '.', $incdot = false, $recursive = false ) {
-		if( $this->is_file($path) ) {
-			$limitFile = basename($path);
-			$path = dirname($path) . '/';
+
+		if ( substr($path, -1) !== '/') {
+			$limit = basename($path);
+			$path = trailingslashit(dirname($path));
 		} else {
-			$limitFile = false;
+			$limit = false;
 		}
 
 		$list = $this->ftp->dirlist($path);
 		if( ! $list )
 			return false;
+
 		if( empty($list) )
 			return array();
 
 		$ret = array();
 		foreach ( $list as $struc ) {
+			if ( $limit && $struc['name'] != $limit )
+				continue;
 
 			if ( 'd' == $struc['type'] ) {
 				$struc['files'] = array();
Index: wp-admin/includes/class-wp-filesystem-ssh2.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-ssh2.php	(revision 10008)
+++ wp-admin/includes/class-wp-filesystem-ssh2.php	(working copy)
@@ -270,7 +291,7 @@
 	function getchmod($file) {
 		$this->debug("getchmod();");
 		$dir = $this->dirlist($file);
-		return $dir[$file]['permsn'];
+		return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
 	}
 
 	function group($file) {
Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 10008)
+++ wp-admin/includes/file.php	(working copy)
@@ -498,7 +498,7 @@
 		if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1)
 			for ( $i = $i + 1; $i <= count($path); $i++ ) {
 				$tmppath = implode('/', array_slice($path, 0, $i) );
-				if ( ! $fs->mkdir($tmppath, 0755) )
+				if ( ! $fs->mkdir($tmppath, FS_CHMOD_DIR) )
 					return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
 			}
 			break; //Exit main for loop
@@ -516,7 +516,7 @@
 			if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here
 				for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please.
 					$tmppath = $to . implode('/', array_slice($path, 0, $i) );
-					if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, 0755) )
+					if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, FS_CHMOD_DIR) )
 						return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
 				}
 				break; //Exit main for loop
@@ -527,7 +527,7 @@
 		if ( ! $file['folder'] ) {
 			if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
 				return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
-			$fs->chmod($to . $file['filename'], 0644);
+			$fs->chmod($to . $file['filename'], FS_CHMOD_FILE);
 		}
 	}
 	return true;
@@ -558,10 +558,10 @@
 				if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
 					return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
 			}
-			$wp_filesystem->chmod($to . $filename, 0644);
+			$wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE);
 		} elseif ( 'd' == $fileinfo['type'] ) {
 			if ( !$wp_filesystem->is_dir($to . $filename) ) {
-				if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
+				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
 					return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
 			}
 			$result = copy_dir($from . $filename, $to . $filename);
@@ -604,6 +604,16 @@
 	if ( !$wp_filesystem->connect() )
 		return false; //There was an erorr connecting to the server.
 
+	//Set the Permission constants if not allready set.
+	if ( ! defined('FS_CHMOD_DIR') || ! defined('FS_CHMOD_FILE') ) {
+		$path = $wp_filesystem->abspath();
+
+		if ( ! defined('FS_CHMOD_DIR') )
+			define('FS_CHMOD_DIR', octdec($wp_filesystem->getchmod($path . 'wp-includes')) );
+		if ( ! defined('FS_CHMOD_FILE') )
+			define('FS_CHMOD_FILE', octdec($wp_filesystem->getchmod($path . 'wp-settings.php')) );
+	}
+
 	return true;
 }
 
Index: wp-admin/includes/update-core.php
===================================================================
--- wp-admin/includes/update-core.php	(revision 10008)
+++ wp-admin/includes/update-core.php	(working copy)
@@ -227,7 +227,7 @@
 	$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
 	$maintenance_file = $to . '.maintenance';
 	$wp_filesystem->delete($maintenance_file);
-	$wp_filesystem->put_contents($maintenance_file, $maintenance_string, 0644);
+	$wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
 
 	// Copy new versions of WP files into place.
 	$result = copy_dir($from . '/wordpress', $to);
Index: wp-admin/includes/update.php
===================================================================
--- wp-admin/includes/update.php	(revision 10008)
+++ wp-admin/includes/update.php	(working copy)
@@ -468,7 +468,7 @@
 		$wp_filesystem->delete($working_dir, true);
 		return new WP_Error('copy_failed', __('Could not copy files'));
 	}
-	$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', 0644);
+	$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
 
 	require(ABSPATH . 'wp-admin/includes/update-core.php');
 

