2

I have setup a aws ec2 linux instnace with sftp server configured.

I am able to send curl command from cli of linux server to aws instance with below command:

curl sftp://username:password@ec2-instance/dir/

But when I use same command from python code as below, it doesn't work

curl_easy_setopt(curl, CURLOPT_UPLOAD, sftp://username:password@ec2-instance/dir);

It says protocol sftp not supported or disabled in curl *closing connection-1 Curl error 1

I am wondering why it works with CLI but not from code. Same is the result when I try with pysftp. Any help would be appreciated. Thanks.

1 Answers1

0

By default the curl command on ubuntu doesn't have sftp enabled, I suggest that you, compile from source by using this gist.

I have tested this to work on ubuntu 18.04 LTS.

This Gist link includes following files:

  • build_curl_sftp.sh file can use them directly on your Ubuntu
    operating system directly.

  • Dockerfile file can build a Docker image with cURL command enabled
    SFTP support and it can use cURL command without polluting original
    cURL command on host operating system.

The same gist is reproduced here for reference:

#!/bin/bash

export CPPFLAGS=-I/usr/local/include
export LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"
export LIBS="-ldl"

sudo sed -i -e "s/# deb-src /deb-src /g" /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y build-essential debhelper libssh-dev

cd /opt/

# Fetch cURL source code
sudo apt-get source curl
sudo apt-get build-dep -y curl
cd curl-*/debian/ && sudo sed -i -e "s@CONFIGURE_ARGS += --without-libssh2@CONFIGURE_ARGS += --with-libssh2@g" rules
cd curl-*/ && sudo dpkg-buildpackage -uc -us -b

# Install rebuilding packages
sudo dpkg -i curl_*.deb
sudo dpkg -i libcurl3-*.deb
sudo dpkg -i libcurl3-gnutls_*.deb
sudo dpkg -i libcurl4-gnutls-dev_7.58.0-2ubuntu3.8_amd64.deb libcurl4_7.58.0-2ubuntu3.8_amd64.deb
Inder
  • 3,711
  • 9
  • 27
  • 42