Blog Post

Azure PaaS Blog
3 MIN READ

Performing Simple SFTP Operations on Azure Blob Storage using CURL Commands

Lavani_Katepaga's avatar
Apr 09, 2025

Introduction

Azure Blob Storage now supports the SFTP protocol, making it easier to interact with blobs using standard tools like curl. This blog guides you through performing simple upload, download, delete, and list operations using curl over SFTP with Azure Blob Storage.

 

Pre-requisites

  1. Azure Blob Storage with SFTP enabled (Storage Account must have hierarchical namespace enabled)
  2. Enable SFTP
  3. Local user created in Azure Storage Account with SSH Key Pair as Authentication method and appropriate container permissions.
  4. Private key (.pem file) for SFTP authentication.
  5. Curl tool installed (version 7.55.0+ for SFTP support)

Please note that the following tests are inclined towards Curl on Windows.

The same can be performed with other OS with appropriate format changes.

 

Authentication Support

When using curl with Azure Blob SFTP, authentication is done via SSH key-based authentication. The user must be associated with a valid public key.

Make sure your .pem file is the private key corresponding to the public key added to the Azure Storage local user.

Note: In this example, we created a local user in the Azure portal and provided SSH key authentication with access to only container1. Since the user is scoped to container1, the curl SFTP connection automatically lands inside that container. That’s why we don’t need to specify container1 in the SFTP URL path.

 

CURL Version Check

To ensure SFTP is supported, verify your curl version:

curl --version

Look for Protocols: ... sftp in the output.

 

SFTP Operations using CURL

 

  1. Uploading a File to Blob Storage
curl -T <File Path on Local> --key <Key path on local Machine> --user <username>: <SFTP Endpoint>/<file-name>

Example:

 

To view detailed logs of the upload or any operation for debugging purposes, you can enable verbose logging by passing the ‘-v’ option in the command.

 

  1. Downloading a File from Blob Storage
curl -o <File Path on Local> --key <Key path on local Machine> --user <username>: <SFTP Endpoint>/<file-name>

Example:

 

  1. Deleting a File from Blob Storage

To delete a file, use curl's --quote option with the rm command:

curl --quote "rm <Path to a file within a container in the storage account>" --key <Key path on local Machine> --user <username>: <SFTP Endpoint>/

Example:

The output showed a list of remaining files/blobs, and text.txt is no longer present.

 

If your blob is inside a subdirectory like test, and the file is named text.txt, then:

curl --quote "rm <subdirectory within a container in the Storage account>/<file>" --key <Key path on local Machine> --user <username>: <SFTP Endpoint>/

 

 

  1. Listing Files in a Container
curl --list-only –key “<Key path on local Machine>" --user "<username>:" "<SFTP Endpoint>/"

Example:

This will return a list of blobs inside container1, because the user is scoped to that container.

 

Common Errors and Fixes

 

Error: Upload failed: No such file or directory (2/-31)

Cause: Target directory (container) doesn’t exist or is not included in user permissions.

Example:

Fix: Ensure the container exists and your SFTP user has access to it.

 

Error: Authentication failed

Cause: Wrong key file or missing user setup.

Example:

Fix: Ensure the .pem file matches the public key added to the local user.

Note: Authentication failures may also be caused by networking restrictions at the account level. For more details, please check Reference links section.

 

Error: Protocol sftp not supported or disabled in libcurl

Cause: CURL version does not support SFTP.

Fix: Upgrade to curl 7.55.0 or above.

 

Conclusion

Using CURL with SFTP is a simple and secure way to interact with Azure Blob Storage. With just a few commands, you can upload, download, delete, or list files programmatically.

This makes CURL a powerful tool for DevOps tasks, automation scripts, and integration workflows!

 

Reference Links

Updated Apr 08, 2025
Version 1.0
No CommentsBe the first to comment