rubio119
rubio119

Reputation: 201

Download file from FTP using Python

I'am trying to dowload a file YYYYMMDD_FCTall.csv from a FTP using Python but the code does not work. This is what I've done:

import pysftp
import time

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

# Make connection to sFTP
with pysftp.Connection("XX.XX.XX.X",
                       username="YYY_YY",
                       password="ZZZZ:",
                       cnopts = cnopts
                       ) as sftp:
    sftp.isfile('/route/route1/route3/FCTall/'+time.strftime("%Y%m%d")+'_FCTall.csv') ## TRUE
    #sftp.get(('/route/route1/route3/FCTall/'+time.strftime("%Y%m%d")+'_FCTall.csv', 'C:/Users/myuser/Documents/Python Scripts/'+time.strftime("%Y%m%d")+'_FCTall.csv')
    sftp.get(''+time.strftime("%Y%m%d")+'_FCTall.csv', 'C:/Users/myuser/Documents/Python Scripts/'+time.strftime("%Y%m%d")+'_FCTall.csv')
    #print(file) ## None

sftp.close()

Upvotes: 0

Views: 96

Answers (1)

M.Rau
M.Rau

Reputation: 1044

Your call to isfile and get are referring different files.

The first is in absolute path. The latter is in relative path to your current FTP directory.

Solution is to align both pathnames. This should solve your problem.

Upvotes: 1

Related Questions