Read a file in buffer from FTP python

后端 未结 3 1334
谎友^
谎友^ 2020-12-01 13:06

I am trying to read a file from an FTP server. The file is a .gz file. I would like to know if I can perform actions on this file while the socket is open. I tr

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 13:41

    That is not possible. To process data on the server, you need to have some sort of execution permissions, be it for a shell script you would send or SQL access.

    FTP is pure file transfer, no execution allowed. You will need either to enable SSH access, load the data into a Database and access that with queries or download the file with urllib then process it locally, like this:

    import urllib
    handle = urllib.urlopen('ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/PMC-ids.csv.gz')
    # Use data, maybe: buffer = handle.read()
    

    In particular, I think the third one is the only zero-effort solution.

提交回复
热议问题