Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ls filename does not work in lftp

Tags:

unix

lftp

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.

like image 517
Gergely Avatar asked Apr 24 '13 07:04

Gergely


People also ask

What is lftp in shell script?

lftp is a file transfer program that allows sophisticated ftp, http and other connections to other hosts. If site is specified then lftp will connect to that site otherwise a connection has to be established with the open command.

How use lftp command in Linux?

Connecting to a remote server The first is by invoking the application from our shell and provide the URL of the remote host, the second is to use the open command, when already in the lftp prompt.

Does lftp support SFTP?

lftp can transfer files via FTP, FTPS, HTTP, HTTPS, FISH, SFTP, BitTorrent, and FTP over HTTP proxy. It also supports the File eXchange Protocol (FXP), which allows the client to transfer files from one remote FTP server to another.

How does the lftp work?

lftp command (lftp Manuel Page) is a file transfer program that allows sophisticated , HTTP, and other connections to other hosts. lftp command has a built-in mirror that can download or update a whole directory tree. There is also a reverse mirror (mirror -R) that uploads or updates a directory tree on the server.


1 Answers

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.

like image 170
Gergely Avatar answered Oct 19 '22 12:10

Gergely