> ## Documentation Index
> Fetch the complete documentation index at: https://dylankenneally-react-native-ssh-sftp-96.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SSHClient

> Core SSH client class for managing connections and operations.

export const EditThisPage = ({filePath}) => {
  const REPO_EDIT_BASE_URL = 'https://github.com/dylankenneally/react-native-ssh-sftp/edit/master';
  return <div className="mt-10 rounded-2xl border border-zinc-950/10 bg-zinc-50 px-4 py-3 dark:border-white/10 dark:bg-white/5">
      <p className="m-0 text-sm text-zinc-600 dark:text-zinc-300">
        See something to improve?{' '}
        <a href={`${REPO_EDIT_BASE_URL}/${filePath}`}>Edit this page on GitHub</a>{' '}
        to suggest a change.
      </p>
    </div>;
};

## Overview

The `SSHClient` class is the main interface for SSH and SFTP operations in the React Native SSH SFTP library. Instances are created using static factory methods rather than the constructor directly.

**Instances should be created using:**

* `SSHClient.connectWithPassword()` - For password authentication
* `SSHClient.connectWithKey()` - For private key authentication

## Constructor

The constructor is **private** and should not be called directly. Use the static factory methods instead.

```typescript theme={null}
constructor(
  host: string,
  port: number,
  username: string,
  passwordOrKey: PasswordOrKey,
  callback: CallbackFunction<void>
)
```

<Note>
  Do not instantiate `SSHClient` directly. Use `connectWithPassword()` or `connectWithKey()` static methods.
</Note>

## Static Methods Overview

The `SSHClient` class provides the following static methods:

### Connection Factory Methods

* `connectWithPassword()` - Create an SSH connection using password authentication
* `connectWithKey()` - Create an SSH connection using private key authentication

For detailed documentation, see [Connection Methods](/api/connection-methods).

### Key Management Methods

* `generateKeyPair()` - Generate a new SSH key pair
* `getKeyDetails()` - Retrieve details about an SSH private key

For detailed documentation, see [Connection Methods](/api/connection-methods).

## Types

### PtyType

Represents the types of PTY (pseudo-terminal) for SSH shell connections.

```typescript theme={null}
enum PtyType {
  VANILLA = 'vanilla',
  VT100 = 'vt100',
  VT102 = 'vt102',
  VT220 = 'vt220',
  ANSI = 'ansi',
  XTERM = 'xterm',
}
```

### CallbackFunction

Represents a callback function with an optional response.

```typescript theme={null}
type CallbackFunction<T> = (error: any, response?: T) => void
```

### EventHandler

Represents an event handler function.

```typescript theme={null}
type EventHandler = (value: any) => void
```

### LsResult

Represents the result of a directory listing operation.

```typescript theme={null}
interface LsResult {
  filename: string;
  isDirectory: boolean;
  modificationDate: string;
  lastAccess: string;
  fileSize: number;
  ownerUserID: number;
  ownerGroupID: number;
  flags: number;
}
```

### KeyPair

Represents a key pair used for SSH authentication.

```typescript theme={null}
interface KeyPair {
  privateKey: string;
  publicKey?: string;
  passphrase?: string;
}
```

### PasswordOrKey

Represents a password or key for authentication.

```typescript theme={null}
type PasswordOrKey = string | KeyPair
```

## Instance Methods

### Event Handling

#### on()

Registers an event handler for the specified event. This method is used to listen to asynchronous events from shell sessions and file transfers.

```typescript theme={null}
on(eventName: string, handler: EventHandler): void
```

**Parameters:**

* `eventName` (string) - The name of the event to listen for. Supported events:
  * `'Shell'` - Receives output from interactive shell sessions
  * `'UploadProgress'` - Receives progress updates during file uploads
  * `'DownloadProgress'` - Receives progress updates during file downloads
* `handler` (EventHandler) - The function to call when the event occurs

**Usage Example:**

```typescript theme={null}
// Listen for shell output
client.on('Shell', (data) => {
  console.log('Shell:', data);
});

// Listen for upload progress
client.on('UploadProgress', (progress) => {
  console.log('Upload progress:', progress);
});

// Listen for download progress
client.on('DownloadProgress', (progress) => {
  console.log('Download progress:', progress);
});
```

### Other Instance Methods

For documentation on other instance methods, see:

* [SSH Operations](/api/ssh/execute) - Execute commands and manage interactive shells
* [SFTP Operations](/api/sftp/connect) - File transfer and remote file system operations
* [Connection Management](/concepts/connection-management) - Disconnect and manage connections

<EditThisPage filePath="docs/api/sshclient.mdx" />
