0

This may be a stupid question. My code works fine and says that I've downloaded each file from the FTP server, but when I go to the folder on my computer where my code is the downloaded files are not there. It has worked in the past but all of sudden I dont know where my files are. What is the problem? Thanks for any help

#Extract UV files from FTP server

import ftplib

try:
# Connection information
server = 'ftp.ncep.noaa.gov'
username = 'anonymous'
password = 'anything'

# Directory and matching information
directory = '/pub/data/nccf/com/hourly/prod/uv.20130729/'#Format:YearMonthDay Remeber to change date
filematch = '*.grib2'

# Establish the connection
ftp = ftplib.FTP(server)
ftp.login(username, password)


# Change to the proper directory
ftp.cwd(directory)



# Loop through matching files and download each one individually
for filename in ftp.nlst(filematch):
    fhandle = open(filename, 'wb')
    print 'Getting ' + filename
    ftp.retrbinary('RETR ' + filename, fhandle.write)
    fhandle.close()
except ftplib.all_errors as err:
print 'Change date on directory'
print err
user_123
  • 62
  • 12
  • Have you tried to print filename to ensure your path is correct? If so, what were the results? – AWainb Jul 29 '13 at 18:42
  • Yes that gives me the filename from the FTP server. It should place each downloaded file from the FTP server to the folder where my code is placed. It has worked in the past. – user_123 Jul 29 '13 at 18:46
  • Are they in your python local directory? (Windows C:\PythonXX\) – Ryan G Jul 29 '13 at 18:46
  • No they are not in the python local directory – user_123 Jul 29 '13 at 18:49
  • I moved the folder previously, so I moved my code to my desktop. And it worked I'm not sure why it wasn't working before. – user_123 Jul 29 '13 at 18:53
  • 1
    They are downloaded to the directory you ran the script from (at least they were for me). change your `fhandle`'s path to something like `"you_directory/"+filename`. – seth Jul 29 '13 at 18:53

0 Answers0