Skip to content

Instantly share code, notes, and snippets.

@bDrwx
Created November 13, 2020 17:10
Show Gist options
  • Save bDrwx/6ae69363c8985f0cf002f6687c45e82a to your computer and use it in GitHub Desktop.
Save bDrwx/6ae69363c8985f0cf002f6687c45e82a to your computer and use it in GitHub Desktop.
last_cdr: str = ''
def callback(info):
ls_out = info.split()
if re.match(r'CF\d{4}.D00', ls_out[-1]):
td = datetime.now() - datetime.strptime(" ".join(ls_out[:2]), '%H.%M:%S %d.%m.%Y')
if td <= timedelta(minutes=15):
global last_cdr
last_cdr = ls_out[-1]
return None
ftp = ftplib.FTP(IP)
ftp.login(name, pass)
ftp.cwd('VIDAST')
ls = ftp.retrlines('LIST ' + 'CF*', callback)
print(f'last_cdr is {last_cdr}')
local_cdr = open(last_cdr, 'wb')
ftp.retrbinary('RETR ' + last_cdr, local_cdr.write)
ftp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment