I have a script that logs into sftp server

eval `ssh-agent -s`
ssh-add /home/<username>/.ssh/id_rsa
sftp <username>@<target>

This works, but I would like to get only files that are newer than certain date. This doesn't seem to be possible with sftp, so I would like to use lftp

If I try to run the same script with lftp

eval `ssh-agent -s`
ssh-add /home/<username>/.ssh/id_rsa
lftp <username>@<target>

I get a prompt for password. Is it possible to use lftp with ssh-agent or is there some other way to avoid supplying the password?

4 Answers 4


It's actually just a wart of LFTP that it even asks for the password. If you provide a dummy password, such as the literal string DUMMY (e.g. lftp sftp://<username>:DUMMY@<target>), lftp won't prompt for a password, and will then subsequently check with the ssh agent. Mind you, if you don't have a key set up, that password will be used.

Alternatively, you can override lftp's sftp:connect-program setting to force ssh to use to a specific key file, without having to set up the agent (the dummy password will still be needed). (One way) this can be done is like so: lftp sftp://<username>:DUMMY@<target> -e 'set sftp:connect-program "ssh -a -x -i <yourprivatekeyfile>"'.

The sftp:connect-program is the option lftp uses to create the sftp session. It defaults to ssh -a -x, but can be pretty much any command (see lftp man page for exact restrictions). Here I'm just tacking on the -i option to force a specific private key.

(NOTE: all the <xxx> bits in the above examples should be replaced with actual values.

To correct a few things in the accepted answer...

  • there isn't an internal FTP server in SSH; sftp is its own protocol, designed as a extension of ssh. It only has "ftp" at the end because it's a file transfer protocol, they share very little in common in terms of details.

  • Also, while LFTP can connect to FTP directly, it can also connect to a ton of other protocols. When connecting with sftp, it directly invokes ssh to handle establishing the connection, and thus all the normal ssh authentication methods apply. The command LFTP uses to invoke ssh can be reconfigured via it's sftp:connect-program option (hence the second alternative listed above).


The easiest way to do this is: lftp -u username, sftp://hostname.

The , character after username does the trick.


An empty password can also be supplied in the site string itself, by inserting a colon after username; lftp sftp://<user>:@<site>


sftp and lftp sound similar but have little in common on the "connection and authentication layer". sftp uses SSH for connection and authentication and uses SSH's internal SFTP server after that is done. In its default mode lftp connects to an FTP server and has no relation to SSH (thus to ssh-agent either). It can connect to SFTP servers, too, but that is not relevant in this case.

  • 9
    in fact, lftp does support sftp, not only ftp. Commented Jan 13, 2018 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .