# New Remote Directory Watcher — SFTP (key-based auth)

> Emit new events when files get created, changed or deleted from a remote directory. See the docs

- Key: `sftp-watch-remote-directory`
- Type: Trigger (Polling)
- Version: 0.1.1
- App: SFTP (key-based auth) (`sftp`) — https://pipedream.com/apps/sftp.md
- This page (HTML): https://pipedream.com/apps/sftp/triggers/watch-remote-directory
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/sftp/sources/watch-remote-directory/watch-remote-directory.mjs

## Description

Emit new events when files get created, changed or deleted from a remote directory. [See the docs](https://github.com/theophilusx/ssh2-sftp-client#orgfac43d1)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `timer` | `$.interface.timer` | Yes | Timer |
| `rootDirectory` | `string` | Yes | Root directory to be watched. example: /public |
| `maxDepth` | `integer` | Yes | Watch all subdirectories within of the root directory, considering the selected maximum depth. |

## Returns

Events emitted by SFTP (key-based auth).

## Run it

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const deployed = await pd.triggers.deploy({
  id: "sftp-watch-remote-directory",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    sftp: { authProvisionId: "apn_xxxxxxx" },
    timer: { "intervalSeconds": 900 },
    rootDirectory: "Root directory",
  },
  webhookUrl: "https://example.com/webhooks/sftp",
})

console.log(deployed.id)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/triggers/deploy \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "sftp-watch-remote-directory",
    "webhook_url": "https://example.com/webhooks/sftp",
    "configured_props": {
      "sftp": { "authProvisionId": "apn_xxxxxxx" },
      "timer": { "intervalSeconds": 900 },
      "rootDirectory": "Root directory"
    }
  }'
```

**MCP**

MCP servers expose SFTP (key-based auth) actions as on-demand tools.

New Remote Directory Watcher is an event source, so your application deploys it with the Connect SDK or API and then either receives each event at a webhook URL or retrieves events on demand with the trigger events API.

## Event delivery

Every event is sent to the HTTP endpoint you choose when you deploy the source. Or: no webhook required — your app or agent can fetch recent events from the [trigger events API](https://pipedream.com/docs/connect/api-reference/list-trigger-events.md) instead.

---

- App: https://pipedream.com/apps/sftp.md · All apps: https://pipedream.com/apps
