0

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()
rubio119
  • 191
  • 1
  • 2
  • 6

1 Answers1

1

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.

M.Rau
  • 764
  • 5
  • 10
  • I almost downvoted this ... but i think you are right ... please post it as an actual answer instead of what is by all rights simply a comment – Joran Beasley Aug 13 '18 at 19:27