--- class-wp-filesystem-ssh2.php	2023-02-17 09:13:28.000000000 +1100
+++ class-wp-filesystem-ssh2-new.php	2023-06-20 15:08:20.899433098 +1000
@@ -70,6 +70,11 @@
 			return;
 		}
 
+                // Get what can be found in DB and/or wp-config.php
+                // This will set any KEY not found to ''
+                $ajaxURL = admin_url('admin-ajax.php');
+                $credentials = request_filesystem_credentials($ajaxURL, 'ssh', false, ABSPATH );
+
 		// Set defaults:
 		if ( empty( $opt['port'] ) ) {
 			$this->options['port'] = 22;
@@ -77,36 +82,75 @@
 			$this->options['port'] = $opt['port'];
 		}
 
+		// Fill ALL $this->options with data required for a proper connection
+		// If a $opt[key] is passed, use that
+		// If a $opt[key] is NOT passed, use $credentials[key] from above
+		// If both not found, raise error
+
+                // Check if hostname is OK
 		if ( empty( $opt['hostname'] ) ) {
-			$this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) );
+			if ( ! empty ( $credentials['hostname'] ) ) {
+				// assign value found in the DB and/or wp-config.php
+				$this->options['hostname'] = $credentials['hostname'];
+
+			} else {
+				// create/raise an error
+				$this->errors->add( 'empty_hostname', __( 'SSH2 credentials (hostname) is required!' ) );
+                                $this->options['hostname'] = '';
+			}
 		} else {
 			$this->options['hostname'] = $opt['hostname'];
 		}
 
-		// Check if the options provided are OK.
+                // Check if username is OK
+                // Needs to be done before the keys!
+		if ( empty( $opt['username'] ) ) {
+			if ( ! empty ( $credentials['username'] ) ) {
+				// assign value found in the DB and/or wp-config.php
+				$this->options['username'] = $credentials['username'];
+			} else {
+				// create/raise an error
+				$this->errors->add( 'empty_username', __( 'SSH2 credentials (username) is required!' ) );
+                                $this->options['username'] = '';
+			}
+		} else {
+			$this->options['username'] = $opt['username'];
+		}
+
+		// Check if the key options provided are OK.
 		if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) {
 			$this->options['public_key']  = $opt['public_key'];
 			$this->options['private_key'] = $opt['private_key'];
-
 			$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' );
-
 			$this->keys = true;
-		} elseif ( empty( $opt['username'] ) ) {
-			$this->errors->add( 'empty_username', __( 'SSH2 username is required' ) );
-		}
-
-		if ( ! empty( $opt['username'] ) ) {
-			$this->options['username'] = $opt['username'];
-		}
+		} else {
+			if ( ! empty( $credentials['public_key'] ) && ! empty ( $credentials['private_key'] ) ) {
+				$this->options['public_key']  = $credentials['public_key'];
+				$this->options['private_key'] = $credentials['private_key'];
+				$this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' );
+				$this->keys = true;
+			} elseif ( empty( $this->options['username'] ) ) {
+				$this->errors->add( 'empty_username', __( 'SSH2 credentials (username) is required when using SSH keys!' ) );
+			}
+                }
 
+                // Check for password OK, only required when not using keys
 		if ( empty( $opt['password'] ) ) {
 			// Password can be blank if we are using keys.
 			if ( ! $this->keys ) {
-				$this->errors->add( 'empty_password', __( 'SSH2 password is required' ) );
+				if ( ! empty ( $credentials['passwrod'] ) ) {
+					// assign value found in the DB and/or wp-config.php
+					$this->options['password'] = $credentials['password'];
+				} else {
+					// create/raise an error
+					$this->errors->add( 'empty_password', __( 'SSH2 credentials (password) is required when not using SSH keys!' ) );
+					$this->options['password'] = '';
+				}
 			}
 		} else {
 			$this->options['password'] = $opt['password'];
 		}
+
 	}
 
 	/**
