Just another WordPress site

SFTP upload Tool

Introduction

The linux sftp client does not support to read the file from stdin. This is especially annoying when you want to do backup your file system, but you do not have enough free disk space to put your tar prior to uploading it to the sftp server.

So we need another client, that does this for us:

  1. sftp_stdin_upload (GPL v3 Licensed)
  2. sftp_stdout_download (GPL v3 Licensed)

You can download the archive with libssh2 from here: marcos_sftp.tar.gz

Build instructions

Requirements:

  1. libssh2 >= 1.2.9
  2. libopenssl >= 1.0 or libgcrypt >= 1.4.5
  3. gcc, standard build tools and libraries ;-)
# extract the archive
tar -xzf marcos_sftp.tgz
export PATH_TO_TAR=`pwd`'/marcos_sftp'
 
# you can skip this if you have at least 1.2.9
# we will build libssh2 1.4.2 (consider to download the latest version):
cd $PATH_TO_TAR/lib_self_compiled/libssh2-1.4.2
./configure --enable-static --with-openssl    # ALTERNATIVE: ./configure --enable-static --with-openssl --with-libgcrypt
make
 
cd $PATH_TO_TAR/marcos_sftp
# in case you use another libssh2 library,
# you might need to change the path LIBSSH2_dir in the Makefile
make ALL    # ALTERNATIVE: make Libcrypt

Known Problems

libssh2 1.4. can hash the known_hosts. To enable this feature you need to comment line 143 and uncomment line 145 in the file $PATH_TO_TAR/marcos_sftp
( Basically you replace LIBSSH2_KNOWNHOST_TYPE_PLAIN by LIBSSH2_KNOWNHOST_TYPE_SAH1 and LIBSSH2_KNOWNHOST_KEYENC_RAW by LIBSSH2_KNOWNHOST_KEYENC_BASE64 in the function libssh2_knownhost_checkp in the file $PATH_TO_TAR/marcos_sftp )

Usage

There is a binary to upload and another to download:

sftp_stdin_openssl
  - Uploads everthing from stdin to a file on the sftp server
      -h sftp hostname 
      -l sftp username
      -p path to public key file    (just key authentication is supported)
      -i path to private key file   (just key authentication is supported)
      -k path to known hosts file
      -f path to the remote file on the sftp server

sftp_stdout_openssl
  - Downloads everthing from a file on the sftp server to stdout
      -h sftp hostname 
      -l sftp username
      -p path to public key file    (just key authentication is supported)
      -i path to private key file   (just key authentication is supported)
      -k path to known hosts file
      -f path to the remote file on the sftp server

Comments on: "SFTP upload Tool" (1)

  1. pweber said:

    You can set the DEBUG_FILENAME option in the Makefile to another location or disable it to get the debugging information on stdout (may interfere with downloads).
    This might be helpful.

Leave a comment for: "SFTP upload Tool"

You must be logged in to post a comment.