3

Can I save a username/password pair for an ftp server in some local configuration file, so that lftp will find them automatically when connecting to that server?

Background: I have script which will be used by multiple users, with different username/password pairs, to sync some generated content from a repository to an ftp server. It would be nice not to have to enter our usernames/passwords by hand each time. Since ftp passwords are sent in cleartext, we are all using low-value passwords for this, so storing the passwords in cleartext in a local config file is acceptable.

PLL
  • 1,572
  • 1
  • 13
  • 21

2 Answers2

16

You can use ~/.netrc file or lftp bookmarks.

Add something like this to ~/.netrc:

machine your.server.example.com login your_login password your_password

Then lftp will pick the password when opening ftp://your_login@your.server.example.com, and it will use your_login automatically when opening "your.server.example.com" without the URL syntax.

When using bookmarks, do "set bmk:save-passwords true" (default is false), then save the current session to bookmarks under a name, then "open bookmark_name" will use the login/password pair. The bookmarks file is plain text, so you can even add the URL with login/password by any text editor. To use a common bookmarks for all users set LFTP_HOME environment variable to a common directory.

cuda12
  • 600
  • 3
  • 15
lav
  • 1,351
  • 9
  • 17
3

Just some more details about lftp bookmarks:

First add line set bmk:save-passwords yes to the main lftp config file /etc/lftp.conf.

Now every user can add his own bookmark:

lftp -c "bookmark add SiteName ftp://user:password@sitename.com/path"

When using lftp in a script just use: lftp -c "open SiteName && lcd MyLocalDir && mput ./"*

vaga
  • 31
  • 1