> ## 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.

# SFTP File Operations

> Manage files on remote servers using SFTP.

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>;
};

## sftpRm()

Removes (unlinks) a file from the remote server using SFTP.

### Signature

```typescript theme={null}
sftpRm(path: string, callback?: CallbackFunction<void>): Promise<void>
```

### Parameters

<ParamField path="path" type="string" required>
  The path of the file to remove on the remote server.
</ParamField>

<ParamField path="callback" type="CallbackFunction<void>" optional>
  Optional callback function to handle the result or error.

  ```typescript theme={null}
  (error: any, response?: void) => void
  ```
</ParamField>

### Returns

<ResponseField name="Promise" type="Promise<void>">
  A promise that resolves when the file is successfully removed, or rejects with an error if the operation fails.
</ResponseField>

### Example

```typescript theme={null}
import SSHClient from '@dylankenneally/react-native-ssh-sftp';

// Using Promise
try {
  await client.sftpRm('/home/user/file.txt');
  console.log('File removed successfully');
} catch (error) {
  console.error('Failed to remove file:', error);
}

// Using callback
client.sftpRm('/home/user/file.txt', (error) => {
  if (error) {
    console.error('Failed to remove file:', error);
    return;
  }
  console.log('File removed successfully');
});
```

***

## sftpRename()

Renames a file or directory on the remote server using SFTP.

### Signature

```typescript theme={null}
sftpRename(oldPath: string, newPath: string, callback?: CallbackFunction<void>): Promise<void>
```

### Parameters

<ParamField path="oldPath" type="string" required>
  The current path of the file or directory on the remote server.
</ParamField>

<ParamField path="newPath" type="string" required>
  The new path to rename the file or directory to.
</ParamField>

<ParamField path="callback" type="CallbackFunction<void>" optional>
  Optional callback function to handle the result or error.

  ```typescript theme={null}
  (error: any, response?: void) => void
  ```
</ParamField>

### Returns

<ResponseField name="Promise" type="Promise<void>">
  A promise that resolves when the file or directory is successfully renamed, or rejects with an error if the operation fails.
</ResponseField>

### Example

```typescript theme={null}
import SSHClient from '@dylankenneally/react-native-ssh-sftp';

// Using Promise
try {
  await client.sftpRename(
    '/home/user/old-name.txt',
    '/home/user/new-name.txt'
  );
  console.log('File renamed successfully');
} catch (error) {
  console.error('Failed to rename file:', error);
}

// Using callback
client.sftpRename(
  '/home/user/old-name.txt',
  '/home/user/new-name.txt',
  (error) => {
    if (error) {
      console.error('Failed to rename file:', error);
      return;
    }
    console.log('File renamed successfully');
  }
);
```

***

## sftpChmod()

Changes the permissions of a file or directory on the remote server using SFTP.

<Warning>
  This method is only available on Android. It will not work on iOS.
</Warning>

### Signature

```typescript theme={null}
sftpChmod(path: string, permissions: number, callback?: CallbackFunction<void>): Promise<void>
```

### Parameters

<ParamField path="path" type="string" required>
  The path of the file or directory on the remote server.
</ParamField>

<ParamField path="permissions" type="number" required>
  The new permissions to set in octal format (e.g., `0o755` or `493`).

  Common permission values:

  * `0o755` (493): Read, write, execute for owner; read and execute for group and others
  * `0o644` (420): Read and write for owner; read-only for group and others
  * `0o600` (384): Read and write for owner only
</ParamField>

<ParamField path="callback" type="CallbackFunction<void>" optional>
  Optional callback function to handle the result or error.

  ```typescript theme={null}
  (error: any, response?: void) => void
  ```
</ParamField>

### Returns

<ResponseField name="Promise" type="Promise<void>">
  A promise that resolves when the permissions are successfully changed, or rejects with an error if the operation fails.
</ResponseField>

### Example

```typescript theme={null}
import SSHClient from '@dylankenneally/react-native-ssh-sftp';

// Using Promise with octal notation
try {
  await client.sftpChmod('/home/user/script.sh', 0o755);
  console.log('Permissions changed successfully');
} catch (error) {
  console.error('Failed to change permissions:', error);
}

// Using Promise with decimal notation
try {
  await client.sftpChmod('/home/user/file.txt', 644);
  console.log('Permissions changed successfully');
} catch (error) {
  console.error('Failed to change permissions:', error);
}

// Using callback
client.sftpChmod('/home/user/script.sh', 0o755, (error) => {
  if (error) {
    console.error('Failed to change permissions:', error);
    return;
  }
  console.log('Permissions changed successfully');
});
```

### Platform Notes

* **Android**: Fully supported
* **iOS**: Not supported

<EditThisPage filePath="docs/api/sftp/file-operations.mdx" />
