lftp handling of negative response to ALLO - ftp

I'm using lftp 4.8.4 on Ubuntu 20.4 with my own ftpd server code.
As the debug log below shows, in preparation for a transfer lftp sends ALLO but appears to ignore the negative response (452 "no space").
I've also tried a 552 "Exceeded storage allocation" response, which was also ignored.
Is there a more appropriate response? Am I misunderstanding the role of ALLO?
Any and all suggestions welcome! Thanks.
> put lfs.img -o lfs3
---- Connecting to ftpd (192.168.0.171) port 21
<--- 220 nil
---> FEAT
<--- 211-Extensions supported:
<--- SIZE
<--- REST STREAM
<--- PASV
<--- 211 END
---> USER anonymous
<--- 331 nil
---> PASS lftp#
<--- 230 nil
---> PWD
<--- 257 /
---> TYPE I
<--- 200 nil
---> PASV
<--- 227 Entering Passive Mode. 192,168,0,171,255,249
---- Connecting data socket to (192.168.0.171) port 65529
---- Data connection established
---> ALLO 72408
<--- 452 no space
---> STOR lfs3
<--- 500 open fail
---- Closing data socket
put: lfs.img: Fatal error: 500 open fail

lftp correctly handles a response of 552 ("Requested file action aborted. Exceeded storage allocation") to an ALLO command. lftp responds to the 552 response with a STOR command, immediately followed by an ABOR (ie. Abort) command.
From RFC 959 (para 4.1.3.): "This command [ALLO] shall be followed by a STORe or APPEnd command." So although the STOR command will not succeed, it would be incorrect to skip it and just send ABOR.

Related

Lftp 550 error when trying to mirror a folder. FileZilla is ok

I made this script to download a folder in a remote FTP with implicit SSL:
open -d ftps://USER:"PASS"#ftp.xxx.tld:990
mirror --verbose --continue /remote/folder $HOME/destination/folder;
bye
It connects, the features are:
<--- 220-Microsoft FTP Service
<--- 220 FTP SOMECOMPANY
---> FEAT
<--- 211-Extended features supported:
<--- LANG EN*
<--- UTF8
<--- AUTH TLS;TLS-C;SSL;TLS-P;
<--- PBSZ
<--- PROT C;P;
<--- CCC
<--- HOST
<--- SIZE
<--- MDTM
<--- REST STREAM
<--- 211 END
But when the mirror command tries to do its thing, it gets:
<--- 257 "/" is current directory.
---> PBSZ 0
---- CWD path to be sent is `/remote/folder'
<--- 200 PBSZ command successful.
---> CWD remote
<--- 550 Access is denied.
mirror: Access failed: 550 Access is denied. (/remote/folder)
---> CWD folder
<--- 550 The system cannot find the file specified.
---> QUIT
When I manually connect with lftp I do have ls access for example but cannot change directory, same error, 550.
On FileZila it works perfectly, I do have access to the folder and can download files. I'm puzzled here. Already tried cryptic things such as using:
lftp -e "set ftp:use-allo false; set ftp:passive-mode true; set ftp:prefer-epsv false;...
to no avail. Any tips? Thanks!
You probably have to force TVFS here by using “set ftp:use-tvfs yes”. It enables Unix-like paths even if the server forgets to announce their support.
As the ftp server is hosted in a Windows envirionment, I had to use \ instead of / for defining paths.

lftp 550 permission denied

i've tried to create a script that will upload some file to a ftp server using lftp, but without any luck so far. If I used build in ftp command in debian I manage to succsessfully connected and put the file.
Here is the debug output from lftp command:
lftp xxx.xxx.xxx.xxxx -e "put -O /out/ some_file_name" -d
---- using user `user01' and password from ~/.netrc
---- Resolving host address...
---- 1 address found:xxx.xxx.xxx.xxxx
---- Connecting to xxx.xxx.xxx.xxxx (xxx.xxx.xxx.xxxx) port 21
<--- 220 (vsFTPd 2.0.7)
---> FEAT
<--- 211-Features:
<--- EPRT
<--- EPSV
<--- MDTM
<--- PASV
<--- REST STREAM
<--- SIZE
<--- TVFS
<--- UTF8
<--- 211 End
---> OPTS UTF8 ON
<--- 200 Always in UTF8 mode.
---> USER user01
<--- 331 Please specify the password.
---> PASS XXXX
<--- 230 Login successful.
---> PWD
<--- 257 "/"
---> TYPE I
<--- 200 Switching to Binary mode.
---> EPSV
<--- 550 Permission denied.
---- Switching passive mode off
---- Closing data socket
---- Closing control socket
As you can see I'm using stored user name and password from .netrc file. I have another script that connect to the same server but uploads files and rename them inside the remote ftp folder using lftp again. Can someone help and explain why I cannot put with lfpt but can do it using ftp.
after add set ftp:passive-mode true and set ftp:prefer-epsv false to /etc/lftp.conf the error is changed
<--- 230 Login successful.
---> PWD
<--- 257 "/"
---> TYPE I
<--- 200 Switching to Binary mode.
---> PASV
<--- 227 Entering Passive Mode (xxx.xxx.xxx.xxx,76,92)
---- Connecting data socket to (xxx.xxx.xxx.xxx) port 19548
---- Data connection established
---> ALLO 710
<--- 550 Permission denied.
---> STOR out/my_file_name
---> ABOR
put: Access failed: 550 Permission denied. (/out/my_file_name)
---- Closing aborted data socket
---- Closing control socket
Okay I've understand what ALLO means
The ALLO command may be sent to a server that requires the necessary space for an uploaded to be reserved before the transfer takes place
so after a quick search in ftp man page, I've found a command to shut it down. After adding set ftp:use-allo false and with epsv false everything is fine now. Thanks alot :)
lftp -e "set ftp:use-allo false; set ftp:passive-mode true; set ftp:prefer-epsv false; mirror -R {local dir} {remote dir}" -u {username},{password} {host}
Use this single command to sync your file from local to server without 550 permission error.
While 550 Permission denied. is a strange response to the EPSV command it means that the server or some middlebox in between does not understand the EPSV command (likely a middlebox since the response to FEAT shows EPSV as supported). If you use the builtin ftp command instead of lftp it will probably use the older PASV command (IPv4 only) instead of the newer EPSV command (IPv4+IPv6 capable).
According to the man page there is a setting ftp:prefer-epsv which should default to false. Maybe some configuration is setting this value to true so that lftp will use EPSV instead of PASV. Check your settings (set -a inside lftp) and if it is true (expected) set it to false and try again, in the hope that it will then use PASV instead of EPSV.

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
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.
The ftp command for binary mode is bin so use that command before you get the file.
cd /direc/tory; bin; get file.xml
The problem is that I see
---> TYPE I
<--- 200 Switching to Binary mode.
in your output, so you're already in binary mode. I wonder if you have a different problem? I also see that you're using passive mode (PASV), and that's good because passive works around firewalls and NATs [1], so we need another reason why you see those timeouts.
Do you have any other clues, maybe from ping or netstat?

Is an FTP error (503 Bad sequence of commands) the result of a client issue or a server issue

I have an FTP server running on an AWS virtual server. We have about 100 users connecting to it over the course of a day, uploading images and other files. All but one are working perfectly. Files come in, not a problem.
We have 1 single user that causes the following log lines to be generated - the username and IP has been removed intentionally and the "***" has been added to highlight the error line:
> 227 Entering Passive Mode (54,79,122,6,195,96)
> STOR media/UV1358A_3.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_3.jpg"
> 226 Successfully transferred "/media/UV1358A_3.jpg"
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,141)
> STOR media/UV1358A_4.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_4.jpg"
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,136)
> 226 Successfully transferred ""
> STOR media/UV1358A_5.jpg
***********************************************
> 503 Bad sequence of commands.
***********************************************
> PASV
> 227 Entering Passive Mode (54,79,122,6,195,80)
> PORT 122,99,115,5,212,227
> 200 Port command successful
> PORT 122,99,115,5,226,227
> 200 Port command successful
> PORT 122,99,115,5,130,124
> 200 Port command successful
> STOR media/UV1358A_9.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_9.jpg"
> PORT 122,99,115,5,152,62
> 200 Port command successful
> STOR media/UV1358A_10.jpg
> 150 Opening data channel for file upload to server of "/media/UV1358A_10.jpg"
> PORT 122,99,115,5,161,49
> 200 Port command successful
We're using FileZilla Server 0.9.55 on a Windows 2012 box.
My question, as stated in the title is essentially.. Is this our issue on the server end, or is this theirs?
Is this 503 error always caused by the FTP client screwing something up or is there the possibility that the FTP server is interpreting something wrongly?
I'm happy to go back to the customer and say "It is our issue", but I suspect it's not at our end.
Thanks
The client sends the PASV command to initiate another file transfer before waiting for the previous transfer (the STOR command) to be finished (226 response):
The first transfer starts:
> PASV
< 227 Entering Passive Mode (54,79,122,6,195,141)
> STOR media/UV1358A_4.jpg
< 150 Opening data channel for file upload to server of "/media/UV1358A_4.jpg"
The PASV command for another transfer before the first transfer finished:
> PASV
< 227 Entering Passive Mode (54,79,122,6,195,136)
The first transfer finishes only now. The filename in the message is missing, because the FileZilla Server resets a file transfer data (including the file name) upon processing of the out-of-order PASV command (it actually should have better rejected the PASV command already with the 503).
> 226 Successfully transferred ""
A request for the another transfer. It fails because the FileZilla server forgets the out-of-order PASV command upon completion of the first file transfer.
> STOR media/UV1358A_5.jpg
< 503 Bad sequence of commands.

FTP Client Output Response standard

After successful FTP file transfer, the the response is used to be "226 File send OK", but suddenly, it has changed to be "226 Transfer complete"
I have below questions:
Does FTP response code has any standard?
Can we customize FTP output response for a specific status code?
Find the standard FTP response for file transfer
$ ftp canopus
Connected to canopus.austin.century.com.
220 canopus.austin.century.com FTP server (Version 4.1 Sat Nov 23 12:52:09 CST 1991) ready.
Name (canopus:eric): dee
331 Password required for dee.
Password:
230 User dee logged in.
ftp> pwd
257 "/home/dee" is current directory.
ftp> cd desktop
250 CWD command successful.
ftp> type ascii
200 Type set to A.
ftp> send typescript
200 PORT command successful.
150 Opening data connection for typescript (128.114.4.99,1412).
226 File send OK.
ftp> cdup
250 CWD command successful.
ftp> bye
221 Goodbye.
Note: suddenly the response text 226 File send OK has changed to 226 Transfer complete
Find the details about FTP responses on wikipedia
RFC 959, 4.2. FTP REPLIES:
An FTP reply consists of a three digit number (transmitted as
three alphanumeric characters) followed by some text. The number
is intended for use by automata to determine what state to enter
next; the text is intended for the human user. It is intended
that the three digits contain enough encoded information that the
user-process (the User-PI) will not need to examine the text and
may either discard it or pass it on to the user, as appropriate.
In particular, the text may be server-dependent, so there are
likely to be varying texts for each reply code.

Resources