SimpleFTPServer icon indicating copy to clipboard operation
SimpleFTPServer copied to clipboard

ftplib can't access the root folder in ESP32/ESP32C3

Open firminxu opened this issue 1 year ago • 6 comments

Hello! Firstly, thanks for the the your good job, I can build my ftp sever easily. I have used version 2.1.7 with my ESP32/ESP32C3 device in PlatformIO environment for a while, it works well. After update it to 2.1.8, I can't access root folder of SD. after I rolled back to 2.1.7, it works again. I tested it with below python code. It will print names of all the files in SD card if it worked.

from ftplib import FTP
def download_and_delete_log_csv_files(host, user, password, remote_dir, local_dir):
    with FTP(host) as ftp:
        try:
            # Attempt to login to the FTP server
            ftp.login(user=user, passwd=password)
            print("Login successful.")
            # Change the current working directory on the server
            ftp.cwd(remote_dir)
            print(f"Changed working directory to {remote_dir}.")

            # Explicitly set passive mode
            ftp.set_pasv(True)

            # Get a list of all files in the remote directory
            files = []
            ftp.retrlines('LIST', lambda line: files.append(line))

            # Print all files in the directory
            print("Files in the remote directory:")
            for file_info in files:
                filename = file_info.split(None, 8)[-1]  # Simplify extracting the filename
                print(filename)

        except Exception as e:
            # Handle any exceptions that occur during the process
            print(f"An error occurred: {e}")

host = '192.168.229.145'
user = 'esp8266'
password = 'esp8266'
remote_dir = '/'  # Directory on the FTP server
local_dir = r'D:\temp'  # Local directory

# Call the function to download and delete log CSV files
download_and_delete_log_csv_files(host, user, password, remote_dir, local_dir)

firminxu avatar Jul 19 '24 05:07 firminxu