'How to read csv from ftp using pandas? [duplicate]

I connected to a sftp and got a list of files successfully:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() )

ssh.connect(Hostname, username=Username, password=Password)

ftp = ssh.open_sftp()
files = ftp.listdir()

dir_oi = "blah"
foi = ftp.listdir(dir_oi)
foi = [i for i in foi if '.csv' in i]
foi = [i for i in foi if not '.test.' in i]
len(foi)

and I get a list of 500+ csvs. I would like to read them to process, but am hitting a block.

remote_file = ( dir_oi +"/" + foi[0])

I tried pd.read_csv(remote_file) and other parimiko suggestions from SO to no avail.

Any suggestions?



Solution 1:[1]

I found this method worked

with ftp.open(remote_file) as f:
    df = pd.read_csv(f, sep = '\t', header = None)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 frank