FTP_CREATE_MISSING_DIRS는 컬 작업입니다 (added here). ftplib을 사용하여 수동으로해야한다는 생각이 들지만 나는 틀린 것으로 입증되기를 원합니다, 누구?
나는 다음과 같은 것을 할 거라고 : (테스트되지 않은, 그리고 ftplib.all_errors
를 잡을 필요)
ftp = ... # Create connection
# Change directories - create if it doesn't exist
def chdir(dir):
if directory_exists(dir) is False: # (or negate, whatever you prefer for readability)
ftp.mkd(dir)
ftp.cwd(dir)
# Check if directory exists (in current location)
def directory_exists(dir):
filelist = []
ftp.retrlines('LIST',filelist.append)
for f in filelist:
if f.split()[-1] == dir and f.upper().startswith('D'):
return True
return False
을 또는이 같은 directory_exists
을 할 수있는 : (열심히 조금 읽을?)
# Check if directory exists (in current location)
def directory_exists(dir):
filelist = []
ftp.retrlines('LIST',filelist.append)
return any(f.split()[-1] == dir and f.upper().startswith('D') for f in filelist)
고마워요. 정확히 내가 찾던 것이 아니었지만 좋은 대답이었습니다. Thanx;) – AliBZ
아니요, 수동으로하지 않아도됩니다. 대신'ftputil' 패키지에서'makedirs' 메소드를 호출 할 수 있습니다. – xApple