---
title: "SFTP REST API - DreamFactory Documentation"
source: "https://wiki.dreamfactory.com/Creating_Sftp_Rest_Api"
canonical_url: "https://wiki.dreamfactory.com/Creating_Sftp_Rest_Api"
converted_at: "2026-04-04T16:14:06.220Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# Creating Sftp Rest Api

	
		From DreamFactory Wiki
		
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		

## Contents

- [1 Creating an SFTP REST API](#Creating_an_SFTP_REST_API)

- [2 Generating the SFTP API and Companion Documentation](#Generating_the_SFTP_API_and_Companion_Documentation)

- [3 Listing Directory Contents](#Listing_Directory_Contents)

- [4 Creating a Folder](#Creating_a_Folder)

- [5 Uploading Files](#Uploading_Files)

- [6 Downloading Files](#Downloading_Files)

- [7 See also](#See_also)

## Creating an SFTP REST API

SFTP (SSH File Transfer Protocol) is the secure version of FTP, capable of transferring data over a Secure Shell (SSH) data stream. Despite the media buzz being focused on file services like Dropbox and AWS S3, SFTP-based file transfers remain an indispensable part of IT infrastructures large and small. But incorporating SFTP functionality into a web application or system management script can be a real drag. Fortunately you can use DreamFactory to easily create a full-featured REST API for your SFTP servers. This API can perform all of the standard tasks associated with an SFTP server, including:

- Creating, listing, updating, and deleting folders

- Creating, listing, retrieving, updating, and deleting files

In this tutorial we'll show you how to configure DreamFactory's SFTP connector, and then walk through several usage examples.

## Generating the SFTP API and Companion Documentation

To generate an SFTP REST API, log in to your DreamFactory instance using an administrator account and select the **API Generation & Connections** tab. Set your API Type to **File**, and then click the purple plus button to establish a new connection:

[![](/images/f/f6/File-api-creation.png)](/File:File-api-creation.png)  [](/File:File-api-creation.png)file api creation
Numerous file storage methods such as AWS S3, Azure Blob, Rackspace, and more are available. There's a lot to review in this menu, but for the moment let's stay on track and search for `SFTP File Storage`:

[![](/images/a/a4/File-api-selection.png)](/File:File-api-selection.png)  [](/File:File-api-selection.png)file api selection
You'll be prompted to supply an API name, label, and description. Keep in mind the name must be lowercase and alphanumeric, as it will be used as the namespace within your generated API URI structure. The label and description are used for reference purposes within the administration console so you're free to title these as you please:

[![](/images/c/c7/Sftp-details.png)](/File:Sftp-details.png)  [](/File:Sftp-details.png)sftp details
Next, you'll scroll down to `Advanced Options`. There you'll supply the SFTP server connection credentials. There are however only 5 required fields:

Field

Description

Host

The SFTP server hostname or IP address.

Port

The SFTP server port. This defaults to 22.

Username

The connecting account username.

Password

The connecting account password.

Root folder

The designated SFTP account root directory.

The other fields (**Timeout**, **Host Finger Print**, **Private Key**) are not always required, and depend upon your particular SFTP server's configuration.

After saving your changes, head over to the `API Docs` tab to review the generated documentation. You'll be presented with a list of 13 generated endpoints:

[![](/images/0/04/Sftp-api-docs.png)](/File:Sftp-api-docs.png)  [](/File:Sftp-api-docs.png)sftp api docs

## Listing Directory Contents

If the root directory you identified during the configuration process already contains a few files and/or directories, click on the `List the folder's content, including properties` endpoint and press `Try It Out`. Doing so will enable all of the supported parameters for this endpoint, allowing you to experiment. Scroll down to the `folder_path` parameter, set it to `/`, and press `Execute`. You should see output similar to the following:

```
{
  &quot;resource&quot;: [
    {
      &quot;path&quot;: &quot;Marketing/&quot;,
      &quot;type&quot;: &quot;folder&quot;,
      &quot;name&quot;: &quot;Marketing&quot;,
      &quot;last_modified&quot;: &quot;Tue, 23 Jul 2019 15:31:31 GMT&quot;
    },
    {
      &quot;path&quot;: &quot;Operations/&quot;,
      &quot;type&quot;: &quot;folder&quot;,
      &quot;name&quot;: &quot;Operations&quot;,
      &quot;last_modified&quot;: &quot;Tue, 23 Jul 2019 15:31:20 GMT&quot;
    }
  ]
}

```

## Creating a Folder

To create a folder, you can use one of two endpoints:

- `POST / Create some folders and/or files`

- `POST /{folder_path}/ Create a folder and/or add content`

These endpoints are identical in functionality, but their URI signatures differ so you might choose one over the other depending upon the desired approach. Let's start by creating a single empty folder. To do so, click on the `POST / Create some folders and/or files` endpoint inside API Docs, press the `Try It Out` button, and enter a folder name in the `X-Folder-Name` field. In the `folder_path` field enter the destination path, such as `/`. Press `Execute` and the folder will be created and a `201` response code returned with a response body that looks like this:

```
{
  &quot;name&quot;: &quot;Marketing&quot;,
  &quot;path&quot;: &quot;Marketing&quot;
}

```

Note the `X-Folder-Name` field is identified as a header, meaning you'll need to handle it accordingly when performing an API call outside of API Docs. The screenshot below shows you how this is handled in the great HTTP testing client Insomnia:

[![](/images/2/22/Sftp-create-directory.png)](/File:Sftp-create-directory.png)  [](/File:Sftp-create-directory.png)sftp create directory

## Uploading Files

To upload a file, you'll send a `POST` request to the SFTP API. You must specify the file name, and can do so either via the URL like this:

```
https://example.com/api/v2/sftp/dreamfactory-ebook.png
```

Alternatively you can use the `X-File-Name` in header to identify file name.

Upload size limitations aren't so much a function of DreamFactory as they are web server configuration. For instance, Nginx' default maximum body size is 1MB, so if you plan on uploading files larger than that you'll need to add the following configuration directive to your `nginx.conf` file:

```
client_max_body_size 10M;

```

You'll know if the `client_max_body_size` setting isn't suffice because you'll receive a `413 Request Entity Too Large` HTTP error if the file size surpasses the setting.

Additionally, you'll receive a `413 Payload Too Large` HTTP error if PHP's `upload_max_filesize` setting isn't suffice. To change this setting you'll open the `php.ini` file associated with the PHP-FPM daemon and modify it accordingly:

```
upload_max_filesize = 100M
```

Don't forget to restart the respective daemons after making changes to the Nginx and PHP configuration files.

## Downloading Files

To download a file you'll send a GET request to the SFTP API, identifying the path and file name in the URL:

```
https://demo.dreamfactory.com/api/v2/sftp/Marketing/df-ebook.png
```

If you're using a tool such as Insomnia, you can view many file types within the response preview:

[![](/images/6/69/Sftp-download-file.png)](/File:Sftp-download-file.png)  [](/File:Sftp-download-file.png)sftp download file
## See also

- [Converting Excel to a JSON Response](/Converting_Excel_To_Json)

- [Creating an AWS S3 REST API](/Creating_Aws_S3_Rest_Api)

- [File System APIs](/File)

Retrieved from "[https://wiki.dreamfactory.com/index.php?title=Creating_Sftp_Rest_Api&oldid=843](https://wiki.dreamfactory.com/index.php?title=Creating_Sftp_Rest_Api&oldid=843)"
		[Categories](/Special:Categories): - [API](/Category:API)
- [Creating](/Category:Creating)
- [SFTP](/Category:SFTP)