Skip to content

Commit 9a48b53

Browse files
authored
Merge pull request #2116 from wiifor/ecoutier_fix_ftp_type
Fixed restoring TYPE I before SIZE after NLST resets transfer mode to ASCII
2 parents 1ab0c83 + 59c957a commit 9a48b53

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • thingsboard_gateway/connectors/ftp

thingsboard_gateway/connectors/ftp/file.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def has_hash(self):
5959
return True if self._hash else False
6060

6161
def get_current_hash(self, ftp):
62+
# ftplib resets transfer type to ASCII after calling NLST (via retrlines).
63+
# SIZE requires binary mode, so we restore it explicitly before calling ftp.size().
64+
ftp.sendcmd("TYPE I")
6265
return crc32((ftp.voidcmd(f'MDTM {self._path_to_file}') + str(ftp.size(self.path_to_file))).encode('utf-8'))
6366

6467
def set_new_hash(self, file_hash):
@@ -72,4 +75,7 @@ def convert_bytes_to_mb(bts):
7275
return round(r, 2)
7376

7477
def check_size_limit(self, ftp):
78+
# ftplib resets transfer type to ASCII after calling NLST (via retrlines).
79+
# SIZE requires binary mode, so we restore it explicitly before calling ftp.size().
80+
ftp.sendcmd("TYPE I")
7581
return self.convert_bytes_to_mb(ftp.size(self.path_to_file)) < self._max_size

0 commit comments

Comments
 (0)