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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With