Skip to content

Commit

Permalink
fix: handle if the path does not exists on the remote
Browse files Browse the repository at this point in the history
  • Loading branch information
CortezSMz committed Sep 20, 2023
1 parent 5f720a9 commit 3ffffdb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/backup_saves.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import socket
import time
from ftplib import FTP
from ftplib import FTP, error_perm
import time

from utils import *
Expand Down Expand Up @@ -89,17 +89,24 @@ def reconnect(self):
logger.debug('Attempt reconnecting after 10s')
self.connect()

def get_files(self, path):
try:
files = self.ftp.nlst(path)
return files
except error_perm:
logger.error(f'The path {path} does not exists on the remote')
return []

def retrieve_saves(self, local_save_folder, remote_folder, children = []):
logger.debug(f'Retrieving saves from {remote_folder} to {local_save_folder}...')
files = children if len(children) else self.ftp.nlst(remote_folder)
files = children if len(children) else self.get_files(remote_folder)
# Create local folder if it's not empty on remote
if len(files):
mk_local_dir(local_save_folder)

downloaded_files = 0
for file in files[:]:
children = self.ftp.nlst(file)
children = self.get_files(file)
# Found a file, download
if children == [file]:
logger.debug(f'Retrieving {file}')
Expand Down

0 comments on commit 3ffffdb

Please sign in to comment.