Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get lftp to use SSL/TLS security mechanism from the command line?

I'm trying to log into an ftps site. I've tried giving the login creds at the command line (and putting set parameters in ~/.lftprc, then opening an lftp session and typing those parameters with lftp job control statements. Regardless, I keep hitting the same roadblock:

 421 Sorry, cleartext sessions are not accepted on this server.
 Please reconnect using SSL/TLS security mechanisms.

I got furthest with the following parameters, but keep getting the error above.

How do I get lftp to use SSL/TLS security mechanism from the command line?

The objective is to script the access to this ftps site using bash (programming without using expect).

 lftp
 lftp :~> set ssl-allow false
 lftp :~> set passive-mode yes
 lftp :~> open ftp.abc.com
 lftp ftp.abc.com:~> login theuser
 Password:
 lftp [email protected]:~> cd
  `cd' at 0 [Delaying before reconnect: 26]
 CTRL-C
 lftp [email protected]:~> debug
 lftp [email protected]:~> cd
 ---- Connecting to ftp.abc.com (XX.XXX.XX.XX) port 21
 <--- 220-Welcome to the Yahoo! Web Hosting FTP server
 <--- 220-Need help? Get all details at:
 <--- 220-http://help.yahoo.com/help/us/webhosting/gftp/
 <--- 220-
 <--- 220-No anonymous logins accepted.
 <--- 220-Yahoo!
 <--- 220-Local time is now 15:30. Server port: 21.
 <--- 220-This is a private system - No anonymous login
 <--- 220 You will be disconnected after 5 minutes of inactivity.
 ---> FEAT
 <--- 211-Extensions supported:
 <---  EPRT
 <---  IDLE
 <---  MDTM
 <---  SIZE
 <---  MFMT
 <---  REST STREAM
 <---  MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
 <---  MLSD
 <---  XDBG
 <---  AUTH TLS
 <---  PBSZ
 <---  PROT
 <---  TVFS
 <---  ESTA
 <---  PASV
 <---  EPSV
 <---  SPSV
 <---  ESTP
 <--- 211 End.
 ---> OPTS MLST type;size;modify;UNIX.mode;UNIX.uid;UNIX.gid;
 <--- 200  MLST OPTS type;size;sizd;modify;UNIX.mode;UNIX.uid;UNIX.gid;unique;
 ---> USER theuser
 <--- 421 Sorry, cleartext sessions are not accepted on this server.
 Please reconnect using SSL/TLS security mechanisms.
like image 540
user2105469 Avatar asked May 27 '14 22:05

user2105469


People also ask

How to use SSL/TLS with FTP?

For use with FTP SSL or TLS, we need to combine these two files into a single “.pem” file. navigate to the directory containing these two files and type in the following command:

Why can't I connect to OpenSSL with lftp?

Perhaps the problem is that the version of OpenSSL your lftp is compiled with is too old to support TLS 1.2? You might try openssl s_client -connect AAA.BBB.CCC.DDD:21 -starttls ftp </dev/null to see if OpenSSL on that system can successfully negotiate a TLS connection with the FTP server without the influence of lftp.

How do I connect to a lftp server?

You need to tell lftp which of the many supported protocols you wish to use. When you connect with the open command you provide the scheme and host in the <scheme>://<hostname> format. For example: ftp://example.org.

How does Pure-FTPd provide FPT SSL/TLS security?

Pure-FTPd can utilize existing server certificates and keys to encrypt our traffic to and from the FTP client. We can achieve FPT SSL/TLS security by providing Pure-FTPd with a certificate and key file combined into one.


2 Answers

It seems like lftp is not configured correctly on many systems, which makes it unable to verify server certificates (producing Fatal error: Certificate verification: Not trusted).

The web (and answers in this post) is full of suggestions to fix this by disabling certificate verification or encryption altogether. This is unsecure as it allows man-in-the-middle attacks to pass unnoticed.

The better solution is to configure certificate verification correctly, which is easy, fortunately. To do so, add the following line to /etc/lftp.conf (or alternatively ~/.lftp/rc, or ~/.config/lftp/rc):

set ssl:ca-file "/etc/ssl/certs/ca-certificates.crt"

ca-certificates.crt is a file that contains all CA certificates of the system. The location used above is the one from Ubuntu and may vary on different systems. To generate or update the file, run update-ca-certificates:

sudo update-ca-certificates

If your system does not have this command, you can create one manually like this:

cat /etc/ssl/certs/*.pem | sudo tee /etc/ssl/certs/ca-certificates.crt > /dev/null
like image 142
ingomueller.net Avatar answered Sep 28 '22 03:09

ingomueller.net


lftp :~> set ssl-allow false

You've explicitly set ssl-allow to false. But this must be true if lftp should attempt to use SSL.

like image 30
Steffen Ullrich Avatar answered Sep 28 '22 03:09

Steffen Ullrich