Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 25017)
+++ wp-includes/functions.php	(working copy)
@@ -1316,7 +1316,7 @@
 	$wrapper = null;
 
 	// strip the protocol
-	if( wp_is_stream( $target ) ) {
+	if ( wp_is_stream( $target ) ) {
 		list( $wrapper, $target ) = explode( '://', $target, 2 );
 	}
 
@@ -1324,7 +1324,7 @@
 	$target = str_replace( '//', '/', $target );
 
 	// put the wrapper back on the target
-	if( $wrapper !== null ) {
+	if ( $wrapper !== null ) {
 		$target = $wrapper . '://' . $target;
 	}
 
@@ -1336,20 +1336,24 @@
 	if ( file_exists( $target ) )
 		return @is_dir( $target );
 
-	// Attempting to create the directory may clutter up our display.
-	if ( @mkdir( $target ) ) {
-		$stat = @stat( dirname( $target ) );
-		$dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.
-		@chmod( $target, $dir_perms );
+	// We need to find the permissions of the parent folder that exists and inherit that.
+	$target_parent = dirname( $target );
+	while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
+		$target_parent = dirname( $target_parent );
+	}
+
+	// Get the permission bits.
+	if ( $target_parent && '.' != $target_parent ) {
+		$stat = @stat( $target_parent );
+		$dir_perms = $stat['mode'] & 0007777;
+	} else {
+		$dir_perms = 0700;
+	}
+
+	if ( @mkdir( $target, $dir_perms, true ) ) {
 		return true;
-	} elseif ( is_dir( dirname( $target ) ) ) {
-			return false;
 	}
 
-	// If the above failed, attempt to create the parent node, then try again.
-	if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) )
-		return wp_mkdir_p( $target );
-
 	return false;
 }
 
