Search code examples
bashftpftp-clientlftp

Force lftp to open binary connections?


The problem: I am trying to create a local mirror of a public FTP site. When I use lftp to do the job it creates a mirror without a problem, but when I try to update the mirror a few days later it becomes very slow due to getting stuck on several files.

Running lftp -d I can see that lftp makes several requests to RETR the file, but these requests result in several **** Timeout - reconnecting messages and after about 2-3 minutes I see

<--- 150 Opening BINARY mode data connection for {filename removed}.`

After this last command the file successfully downloads and lftp proceeds further.

From the manual I understand that BINARY is the default mode for lftp, but somehow it doesn't seem to work for the early requests. Can someone suggest how I can force lftp to always open BINARY mode data connection to download all files?

Here's a MWE:

``lftp -d -u anonymous,anonymous -c "open {url}; get {file}"``

And response from lftp -d:

---- Connecting to {url} ({IP}) port 21
<--- 220 (vsFTPd 3.0.3)                          
---> FEAT
<--- 211-Features:                                     
<---  EPRT
<---  EPSV
<---  MDTM
<---  PASV
<---  REST STREAM
<---  SIZE
<---  TVFS
<--- 211 End
---> USER anonymous
<--- 331 Please specify the password.            
---> PASS anonymous
<--- 230 Login successful.                                      
---> TYPE I
<--- 200 Switching to Binary mode.                         
---> SIZE {file}
<--- 213 3321                                              
---> MDTM {file}
--- 213 20160318190446                                         
---> PASV
<--- 227 Entering Passive Mode ({IP}).        
---- Connecting data socket to ({IP}) port 55380
---- Data connection established                                  
---> RETR {file}
**** Timeout - reconnecting                                     
---- Closing data socket
---- Closing control socket

Solution

  • lftp uses binary mode by default for all file transfers and ascii mode for directory listings. So the binary mode should not be a problem here.

    Maybe you have a subtle connectivity problem, sometimes setting net:socket-maxseg to a lower value (e.g. 500) helps.