Index: wp-admin/includes/class-wp-filesystem-ssh2.php
===================================================================
--- wp-admin/includes/class-wp-filesystem-ssh2.php	(revision 8875)
+++ 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']));
@@ -202,7 +205,7 @@
 	}
 
 	function put_contents($file, $contents, $type = '' ) {
-		$this->debug("put_contents();");
+		$this->debug("put_contents($file);");
 		$tempfile = wp_tempnam( $file );
 		$temp = fopen($tempfile, 'w');
 		if ( ! $temp )
@@ -326,7 +329,7 @@
 	function is_dir($path) {
 		$this->debug("is_dir();");
 		//DO NOT RELY ON dirlist()!
-		$list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', rtrim($path, '/'))));
+		$list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', untrailingslashit($path))));
 		if ( ! $list )
 			return false;
 		else
@@ -359,7 +362,7 @@
 	
 	function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
 		$this->debug("mkdir();");
-		$path = trim($path, '/');
+		$path = untrailingslashit($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 8875)
+++ wp-admin/includes/file.php	(working copy)
@@ -386,7 +386,7 @@
 	if ( 0 == count($archive_files) )
 		return new WP_Error('empty_archive', __('Empty archive'));
 
-	$path = explode('/', $to);
+	$path = explode('/', untrailingslashit($to));
 	for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/'
 		$tmppath = implode('/', array_slice($path, 0, $i) );
 		if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1)
@@ -401,13 +401,16 @@
 
 	$to = trailingslashit($to);
 	foreach ($archive_files as $file) {
-		$path = explode('/', $file['filename']);
-		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
+		$path = $file['folder'] ? $file['filename'] : dirname($file['filename']);
+		$path = explode('/', $path);
+		for ( $i = count($path); $i >= 0; $i-- ) { //>=0 as the first element contains data
+			if ( empty($path[$i]) )
+				continue;
 			$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.
 					$tmppath = $to . implode('/', array_slice($path, 0, $i) );
-					if ( ! $fs->mkdir($tmppath, 0755) )
+					if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, 0755) )
 						return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
 				}
 				break; //Exit main for loop
@@ -503,8 +506,7 @@
 	if ( 'direct' == $type )
 		return true;
 
-	if( ! $credentials = get_option('ftp_credentials') )
-		$credentials = array();
+	$credentials = get_option('ftp_credentials', array());
 	// 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']);
@@ -521,7 +523,7 @@
 		$credentials['connection_type'] = 'ssh';
 	else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) )
 		$credentials['connection_type'] = 'ftps';
-	else
+	else if ( !isset($credentials['connection_type']) || (isset($_POST['connection_type']) && 'ftp' == $_POST['connection_type']) )
 		$credentials['connection_type'] = 'ftp';
 
 	if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
@@ -547,17 +549,16 @@
 <!--
 jQuery(function($){
 	jQuery("#ssh").click(function () {
-		jQuery("#ssh_keys").show();		
+		jQuery("#ssh_keys").show();
 	});
 	jQuery("#ftp").click(function () {
-		jQuery("#ssh_keys").hide();		
+		jQuery("#ssh_keys").hide();
 	});	
 	jQuery("#ftps").click(function () {
-		jQuery("#ssh_keys").hide();		
+		jQuery("#ssh_keys").hide();
 	});
 	jQuery(document).ready(function(){
-		if ( jQuery("#ssh:checked").length )
-		{
+		if ( jQuery("#ssh:checked").length ) {
 			jQuery("#ssh_keys").show();
 		}
 	});
@@ -566,8 +567,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>
@@ -589,9 +590,9 @@
 <th scope="row"><?php _e('Connection Type') ?></th>
 <td>
 <fieldset><legend class="hidden"><?php _e('Connection Type') ?> </legend>
-<p><label><input id="ftp" name="connection_type"  type="radio" value="ftp" <?php checked('ftp', $connection_type); ?>	/> <?php _e('FTP') ?></label><br />
-<label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br />
-<?php if ( extension_loaded('ssh2') ) { ?><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label><?php } ?></p>
+<p><label><input id="ftp" name="connection_type"  type="radio" value="ftp" <?php checked('ftp', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('FTP') ?></label><br />
+<label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); if ( defined('FTP_SSH') || defined('FTP_SSH') ) echo ' disabled="disabled"';  ?>/> <?php _e('FTPS (SSL)') ?></label><br />
+<?php if ( extension_loaded('ssh2') ) { ?><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type);  if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('SSH') ?></label><?php } ?></p>
 </fieldset>
 </td>
 </tr>
