Index: wp-admin/includes/class-wp-filesystem-ssh2.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-ssh2.php	(revision 8878)
+++ wp-admin/includes/class-wp-filesystem-ssh2.php	(working copy)
@@ -63,7 +63,7 @@
 		$this->method = 'ssh2';
 		$this->errors = new WP_Error();
 
-		//Check if possible to use ftp functions.
+		//Check if possible to use ssh2 functions.
 		if ( ! extension_loaded('ssh2') ) {
 			$this->errors->add('no_ssh2_ext', __('The ssh2 PHP extension is not available'));
 			return false;
@@ -89,7 +89,7 @@
 		else
 			$this->options['username'] = $opt['username'];
 
-		if (( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) )) {
+		if ( ( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) ) ) {
 			$this->options['public_key'] = $opt['public_key'];	
 			$this->options['private_key'] = $opt['private_key'];
 			
@@ -99,20 +99,23 @@
 		}
 
 
-		if ( empty ($opt['password']) )
+		if ( empty ($opt['password']) ) {
 			if ( !$this->keys )	//	 password can be blank if we are using keys
 				$this->errors->add('empty_password', __('SSH2 password is required'));
-		else
+		} else {
 			$this->options['password'] = $opt['password'];
+		}
 			
 	}
 
 	function connect() {
 		$this->debug("connect();");
-		if ( ! $this->keys )
-			$this->link = @ssh2_connect($this->options['hostname'], $this->options['port']);
-		else
-			$this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']);	
+		
+		if ( ! $this->keys ) {
+			$this->link = @ssh2_connect($this->options['hostname'], $this->options['port']);			
+		} else {
+			$this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']);			
+		}
 			
 		if ( ! $this->link ) {
 			$this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
@@ -359,7 +362,7 @@
 	
 	function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
 		$this->debug("mkdir();");
-		$path = trim($path, '/');
+		$path = rtrim($path, '/');
 		if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
 			return false;
 		if( $chown )
Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 8878)
+++ wp-admin/includes/file.php	(working copy)
@@ -405,7 +405,7 @@
 		for ( $i = count($path) - 1; $i >= 0; $i-- ) { //>=0 as the first element contains data, count()-1, as we do not want the file component
 			$tmppath = $to . implode('/', array_slice($path, 0, $i) );
 			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.
+				for ( $i = $i + 1; $i < count($path); $i++ ) { //< count() no file component please.
 					$tmppath = $to . implode('/', array_slice($path, 0, $i) );
 					if ( ! $fs->mkdir($tmppath, 0755) )
 						return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
@@ -503,8 +503,8 @@
 	if ( 'direct' == $type )
 		return true;
 
-	if( ! $credentials = get_option('ftp_credentials') )
-		$credentials = array();
+	$credentials = get_option('ftp_credentials');
+
 	// If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
 	$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
 	$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
@@ -517,14 +517,14 @@
 	if ( strpos($credentials['hostname'], ':') )
 		list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
 
-	if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) )
+	if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) || $credentials['connection_type'] == 'ssh' )
 		$credentials['connection_type'] = 'ssh';
-	else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) )
+	else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) || $credentials['connection_type'] == 'ftps' )
 		$credentials['connection_type'] = 'ftps';
 	else
 		$credentials['connection_type'] = 'ftp';
-
-	if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
+	
+	if ( !$error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
 		$stored_credentials = $credentials;
 		unset($stored_credentials['password'], $stored_credentials['private_key'], $stored_credentials['public_key']);
 		update_option('ftp_credentials', $stored_credentials);
@@ -566,8 +566,8 @@
 </script>
 <form action="<?php echo $form_post ?>" method="post">
 <div class="wrap">
-<h2><?php _e('FTP Connection Information') ?></h2>
-<p><?php _e('To perform the requested action, FTP connection information is required.') ?></p>
+<h2><?php _e('Connection Information') ?></h2>
+<p><?php _e('To perform the requested action, connection information is required.') ?></p>
 <table class="form-table">
 <tr valign="top">
 <th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
