[projects/pld-ftp-admin] ftpiod: send and read the whole gett reply

arekm arekm at pld-linux.org
Sat Oct 24 11:45:44 CEST 2026


commit cc061e36a379f470d26a5b48a9dcb3de2f7cd8ed
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Oct 20 18:38:36 2026 +0200

    ftpiod: send and read the whole gett reply
    
    Lists larger than the socket buffer (about 200 KB) were cut short.

 modules/cmds.py  | 14 +++++++++-----
 modules/ftpio.py | 13 +++++++++++--
 2 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/modules/cmds.py b/modules/cmds.py
index c3e53bf..dae454d 100644
--- a/modules/cmds.py
+++ b/modules/cmds.py
@@ -170,11 +170,15 @@ def cmd_gettree(con):
         else:
             line=line+'\n0'
         buf=buf+'\0'+line
-    if buf:
-        con.sock.send(bytearray('%.6d' % (len(buf)-1), encoding='utf-8'))
-        con.sock.send(bytearray(buf[1:], encoding='utf-8'))
-    else:
-        con.sock.send(bytearray('000000', encoding='utf-8'))
+    data=buf[1:].encode('utf-8')
+    # the socket is non-blocking and a long list does not fit its buffer
+    con.sock.settimeout(10)
+    try:
+        con.sock.sendall(f'{len(data):010d}'.encode() + data)
+    except OSError:
+        raise BailOut()
+    finally:
+        con.sock.setblocking(False)
 
 
 cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
diff --git a/modules/ftpio.py b/modules/ftpio.py
index 59cb55c..148c7da 100644
--- a/modules/ftpio.py
+++ b/modules/ftpio.py
@@ -80,12 +80,21 @@ def locks_dump():
 #    ret = sock.recv(nbytes).decode("utf-8")
     return ret
 
+def recvall(size):
+    data=b''
+    while len(data) < size:
+        chunk=sock.recv(size - len(data))
+        if not chunk:
+            raise ConnectionError('ftpiod closed the connection')
+        data+=chunk
+    return data
+
 def gettree():
     sock.send(bytearray('gett\0', encoding='utf-8'))
     pkgs=[]
-    len=int(sock.recv(6).decode("utf-8"))
+    len=int(recvall(10).decode("utf-8"))
     if len:
-        for pkg in sock.recv(len).decode("utf-8").split('\0'):
+        for pkg in recvall(len).decode("utf-8").split('\0'):
             tmp=pkg.split('\n')
             pkgs.append((tmp[0], int(tmp[1]), int(tmp[2])))
     return pkgs
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/e14cb7d4d74f8bdd9368d9645ecaf49593cf6335



More information about the pld-cvs-commit mailing list