Documentation Index
Fetch the complete documentation index at: https://dylankenneally-react-native-ssh-sftp-96.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Connection Lifecycle
The React Native SSH SFTP library manages SSH and SFTP connections through a well-defined lifecycle. Understanding this lifecycle is crucial for proper resource management.Creating Connections
Connections are created using factory methods on theSSHClient class:
SSH vs SFTP Connections
The library maintains separate connection states for SSH and SFTP operations:- SSH Connection: Established when you create a client instance
- SFTP Connection: Established when you first use an SFTP method or explicitly call
connectSFTP()
SSH Connection
The SSH connection is automatically established during client creation and allows you to:- Execute commands via
execute() - Start and interact with shell sessions via
startShell(),writeToShell() - Use as a base for SFTP operations
SFTP Connection
The SFTP connection is established on-demand and allows file transfer operations.When to Call connectSFTP()
TL;DR: Calling
connectSFTP() is optional. All SFTP methods automatically establish the connection if needed.Automatic Connection
All SFTP methods (sftpLs, sftpDownload, sftpUpload, etc.) automatically call an internal checkSFTP() method that establishes the connection if it’s not already active:
Explicit Connection
You may want to callconnectSFTP() explicitly to:
- Separate connection from operation: Establish the connection early to reduce latency on first SFTP operation
- Handle connection errors separately: Catch connection errors before attempting file operations
- Verify SFTP availability: Test if SFTP is available on the server
Method Signature
Disconnecting Properly
Proper disconnection is essential to free up resources and prevent connection leaks.Disconnect SFTP
UsedisconnectSFTP() to close the SFTP connection while keeping the SSH connection active:
On iOS,
disconnectSFTP() has limited functionality due to native implementation constraints. The SSH disconnect() method will properly close the SFTP stream on all platforms.Disconnect SSH
Usedisconnect() to close all active connections (shell, SFTP, and SSH):