0

I'm working on a client-server program that uses FTP and right now I'm trying to figure out a way to list the directories from a local host and display the file name and file size. I know how to do this from an external host, but I'm not sure how to convert it into a local host.

FTP_HOST = " "
FTP_USER = "anonymous"
FTP_PASS = ""
# some utility functions that we gonna need
def get_size_format(n, suffix="B"):
    # converts bytes to scaled format (e.g KB, MB, etc.)
    for unit in ["", "K", "M", "G", "T", "P"]:
        if n < 1024:
            return f"{n:.2f}{unit}{suffix}"
        n /= 1024
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Your local ftp accept anonymous connections? try to set `FTP_HOST = 'localhost'`. Depending on your ftp settings you have to set the username and password. – Carlo Zanocco Oct 14 '20 at 15:11

1 Answers1

0

You do not need FTP to access local files.

Just access the files directly. See How do I list all files of a directory?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992