-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automation of downloading data from AVRIS-NG
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from ftplib import FTP | ||
import os, sys, os.path | ||
|
||
def handleDownload(block): | ||
file.write(block) | ||
print ".", | ||
|
||
ddir='/Users' # set to local path where you want files downloaded to | ||
os.chdir(ddir) | ||
ftp = FTP('avng.jpl.nasa.gov') | ||
|
||
print 'Logging in.' | ||
ftp.login() | ||
directory = '/AVNG_2015_data_distribution/L2/' | ||
print 'Changing to ' + directory | ||
ftp.cwd(directory) | ||
|
||
dirnames = ftp.nlst() # get list of directories | ||
print dirnames | ||
|
||
#for each directory, download the directory and its contents to local computer | ||
for dirname in dirnames: | ||
print 'Changing to ' + dirname | ||
ftp.cwd(dirname) | ||
filenames = ftp.nlst() # get list of filenames in directory | ||
print filenames | ||
count = 0 | ||
localpath = ddir + '/' + dirname | ||
os.mkdir(localpath) # create this directory locally | ||
#download each file to the newly created local directory | ||
for filename in filenames: | ||
local_filename = os.path.join(localpath, filename) | ||
file = open(local_filename, 'wb') | ||
ftp.retrbinary('RETR '+ filename, file.write) | ||
file.close() | ||
|
||
ftp.cwd('..') | ||
|
||
ftp.quit() | ||
|