ls filename does not work in lftp

Gergely picture Gergely · Apr 24, 2013 · Viewed 9.2k times · Source

I created an lftp script to upload single files to a web hosting provider.

The use case is that I call it from the repository root, so the relative path is the same here and in the remote server.

#!/bin/bash

DIRNAME=$(dirname $1)
FILENAME=$(basename $1)
REPO_ROOT=$(pwd)
ABSOLUTE_PATH=${REPO_ROOT}/$1

lftp -u user,passwd -p port sftp://user@hosting <<EOF
cd $DIRNAME
put  $ABSOLUTE_PATH 
ls -l $FILENAME
quit 0
EOF

It works, with one small but annoying bug. To check that it really uploads the file, I have put an ls -l at the end. It fails and I do not understand why:

ls: Access failed: No such file(functions.php)   

I tried to use rels and cache flush but in vain. I'm using lftp 4.0.9.

Answer

Gergely picture Gergely · Apr 24, 2013

Some googling at last gave a result in mail-archive

It is a limitation of SFTP protocol implementation in lftp. It cannot list a single file, only a specific directory.

Fortunately, lftp allows pipes, so

ls -l | grep  "$FILENAME"

solves the problem.