Skip to content

Commit

Permalink
Added new datetime format to support windows FTP Server
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 19, 2024
1 parent 8c774d8 commit d5d9f9b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/aioftp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,23 @@ def parse_list_line_windows(self, b):
date_time_str = line[: date_time_end + 1].strip().split(" ")
date_time_str = " ".join([x for x in date_time_str if len(x) > 0])
line = line[date_time_end + 1 :].lstrip()

possible_formats = ["%m/%d/%Y %I:%M %p", "%m-%d-%y %I:%M%p"]
date_time = None
with setlocale("C"):
strptime = datetime.datetime.strptime
date_time = strptime(date_time_str, "%m/%d/%Y %I:%M %p")
for fmt in possible_formats:
try:
date_time = datetime.datetime.strptime(date_time_str, fmt)
break
except ValueError:
continue
if not date_time:
raise ValueError(f"Date/time format not recognized: {date_time_str}")

info = {}
info["modify"] = self.format_date_time(date_time)
next_space = line.index(" ")

if line.startswith("<DIR>"):
info["type"] = "dir"
else:
Expand All @@ -520,6 +531,7 @@ def parse_list_line_windows(self, b):
filename = line[next_space:].lstrip()
if filename == "." or filename == "..":
raise ValueError

return pathlib.PurePosixPath(filename), info

def parse_list_line(self, b):
Expand Down

0 comments on commit d5d9f9b

Please sign in to comment.