---
title: "View source for Creating Sftp Rest Api - DreamFactory Wiki"
source: "https://wiki.dreamfactory.com/index.php?action=edit&title=Creating_Sftp_Rest_Api"
canonical_url: "https://wiki.dreamfactory.com/index.php?action=edit&title=Creating_Sftp_Rest_Api"
converted_at: "2026-11-25T07:13:16.645Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for Creating Sftp Rest Api

	
		
		← [Creating Sftp Rest Api](/Creating_Sftp_Rest_Api)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=SFTP REST API - DreamFactory Documentation
|title_mode=replace
|description=Create a full-featured REST API for SFTP servers to manage files and folders with DreamFactory.
|keywords=DreamFactory, SFTP, REST API, file transfer, SSH, file management
|canonical=https://wiki.dreamfactory.com/Creating_Sftp_Rest_Api
|og:title=SFTP REST API
|og:type=article
|og:site_name=DreamFactory Documentation
|og:description=Create a full-featured REST API for SFTP servers to manage files and folders with DreamFactory.
}}
&lt;span id="creating-an-sftp-rest-api">&lt;/span>
== 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.

&lt;span id="generating-the-sftp-api-and-companion-documentation">&lt;/span>
== 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 &amp;amp; Connections''' tab. Set your API Type to '''File''', and then click the purple plus button to establish a new connection:

[[File:file-api-creation.png|thumb|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 &lt;code>SFTP File Storage&lt;/code>:

[[File:file-api-selection.png|thumb|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:

[[File:sftp-details.png|thumb|sftp details]]
Next, you'll scroll down to &lt;code>Advanced Options&lt;/code>. There you'll supply the SFTP server connection credentials. There are however only 5 required fields:

{| class="wikitable"
|-
! 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 &lt;code>API Docs&lt;/code> tab to review the generated documentation. You'll be presented with a list of 13 generated endpoints:

[[File:sftp-api-docs.png|thumb|sftp api docs]]
&lt;span id="listing-directory-contents">&lt;/span>
== Listing Directory Contents ==

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

&lt;syntaxhighlight lang="text">
{
  &amp;quot;resource&amp;quot;: [
    {
      &amp;quot;path&amp;quot;: &amp;quot;Marketing/&amp;quot;,
      &amp;quot;type&amp;quot;: &amp;quot;folder&amp;quot;,
      &amp;quot;name&amp;quot;: &amp;quot;Marketing&amp;quot;,
      &amp;quot;last_modified&amp;quot;: &amp;quot;Tue, 23 Jul 2019 15:31:31 GMT&amp;quot;
    },
    {
      &amp;quot;path&amp;quot;: &amp;quot;Operations/&amp;quot;,
      &amp;quot;type&amp;quot;: &amp;quot;folder&amp;quot;,
      &amp;quot;name&amp;quot;: &amp;quot;Operations&amp;quot;,
      &amp;quot;last_modified&amp;quot;: &amp;quot;Tue, 23 Jul 2019 15:31:20 GMT&amp;quot;
    }
  ]
}
&lt;/syntaxhighlight>
&lt;span id="creating-a-folder">&lt;/span>
== Creating a Folder ==

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

* &lt;code>POST / Create some folders and/or files&lt;/code>
* &lt;code>POST /{folder_path}/ Create a folder and/or add content&lt;/code>

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 &lt;code>POST / Create some folders and/or files&lt;/code> endpoint inside API Docs, press the &lt;code>Try It Out&lt;/code> button, and enter a folder name in the &lt;code>X-Folder-Name&lt;/code> field. In the &lt;code>folder_path&lt;/code> field enter the destination path, such as &lt;code>/&lt;/code>. Press &lt;code>Execute&lt;/code> and the folder will be created and a &lt;code>201&lt;/code> response code returned with a response body that looks like this:

&lt;syntaxhighlight lang="text">
{
  &amp;quot;name&amp;quot;: &amp;quot;Marketing&amp;quot;,
  &amp;quot;path&amp;quot;: &amp;quot;Marketing&amp;quot;
}
&lt;/syntaxhighlight>
Note the &lt;code>X-Folder-Name&lt;/code> 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:

[[File:sftp-create-directory.png|thumb|sftp create directory]]
&lt;span id="uploading-files">&lt;/span>
== Uploading Files ==

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

&lt;pre>https://example.com/api/v2/sftp/dreamfactory-ebook.png&lt;/pre>
Alternatively you can use the &lt;code>X-File-Name&lt;/code> 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 &lt;code>nginx.conf&lt;/code> file:

&lt;syntaxhighlight lang="text">
client_max_body_size 10M;
&lt;/syntaxhighlight>
You'll know if the &lt;code>client_max_body_size&lt;/code> setting isn't suffice because you'll receive a &lt;code>413 Request Entity Too Large&lt;/code> HTTP error if the file size surpasses the setting.

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

&lt;pre>upload_max_filesize = 100M&lt;/pre>
Don't forget to restart the respective daemons after making changes to the Nginx and PHP configuration files.

&lt;span id="downloading-files">&lt;/span>
== 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:

&lt;pre>https://demo.dreamfactory.com/api/v2/sftp/Marketing/df-ebook.png&lt;/pre>
If you're using a tool such as Insomnia, you can view many file types within the response preview:

[[File:sftp-download-file.png|thumb|sftp download file]]

== See also ==
* [[Converting_Excel_To_Json|Converting Excel to a JSON Response]]
* [[Creating_Aws_S3_Rest_Api|Creating an AWS S3 REST API]]
* [[File|File System APIs]]

[[Category:API]]
[[Category:Creating]]
[[Category:SFTP]]

[[Category:API]]
Return to [Creating Sftp Rest Api](/Creating_Sftp_Rest_Api).

Retrieved from "[https://wiki.dreamfactory.com/Creating_Sftp_Rest_Api](https://wiki.dreamfactory.com/Creating_Sftp_Rest_Api)"