한글 설명 : ftp 특정폴더가 여러 비교대상별로 글자는 같으나 대소문자가 달라서 ftp 폴더이름을 특정할 수 없는 경우, 폴더리스트를 받아서 대소문자 구분없이 글자만 가지고 비교를 한 후 일치하는 폴더명을 그대로 가져와서 접속에 활용한다.
1. Fetch All Directory Names and Compare : You can fetch all directory names from the server and then see if any match with your desired folder name, ignoring case.
2. Use Regular Expressions : You could use regular expressions to make a case-insensitive match.
Here’s some example code using Python’s `ftplib`:
“`python
from ftplib import FTP
def find_folder_ignoring_case(ftp, target_folder):
folder_names = ftp.nlst() # Get list of all files/folders in the current directory
for folder in folder_names:
if folder.lower() == target_folder.lower():
return folder
return None
# Connect to FTP server
ftp = FTP(‘ftp.example.com’)
ftp.login(‘username’, ‘password’)
# Target folder name (case insensitive)
target_folder = ‘MyFolder’
# Find the actual folder name
actual_folder = find_folder_ignoring_case(ftp, target_folder)
if actual_folder:
ftp.cwd(actual_folder) # Navigate into the folder
else:
print(f”Folder {target_folder} not found.”)
“`
This code will look for a folder that matches your desired folder name without considering case, and then navigate into it.