Skip to main content

connectSFTP()

Connects to the SFTP server.
It is not mandatory to call this method before calling any SFTP method. The library will automatically establish an SFTP connection when needed.

Signature

connectSFTP(callback?: CallbackFunction<void>): Promise<void>

Parameters

callback
CallbackFunction<void>
Optional callback function to be called after the connection is established.
(error: any, response?: void) => void

Returns

Promise
Promise<void>
A promise that resolves when the connection is established successfully, or rejects with an error if the connection fails.

Example

import SSHClient from '@dylankenneally/react-native-ssh-sftp';

// Using Promise
await client.connectSFTP();
console.log('SFTP connected');

// Using callback
client.connectSFTP((error) => {
  if (error) {
    console.error('SFTP connection failed:', error);
    return;
  }
  console.log('SFTP connected');
});

disconnectSFTP()

Disconnects the SFTP connection.
On iOS, this method has limited functionality. The SFTP stream will be closed when the SSH connection is disconnected using disconnect().

Signature

disconnectSFTP(): void

Parameters

None

Returns

void
void
This method does not return a value.

Example

import SSHClient from '@dylankenneally/react-native-ssh-sftp';

// Disconnect SFTP
client.disconnectSFTP();
console.log('SFTP disconnected');

Platform Notes

  • Android: Fully supported. Explicitly closes the SFTP channel.
  • iOS: The SFTP stream will be closed when disconnect() is called on the SSH client.