Using lftp with ssh-agent

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>