You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

ftp file retrieval using wildcard   Robert Ehrman Jun 14, 2006
Re: ftp file retrieval using wildcard   Petr K. Jun 14, 2006
Re: ftp file retrieval using wildcard   Robert Ehrman Jun 15, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject ftp file retrieval using wildcard 
Author Robert Ehrman 
Date Jun 14, 2006 
Message I'm trying to figure out how to retrieve a file from an FTP site using a wildcard. The file name always starts with the letters 'JAX' as in 'JAX_xxxx.tar.gz'. and I'm certain there is a way, using a wildcard, to download just that specific file. I've attached the code, line 22 is the line I can't figure out. It works this way, when I specify the entire file name, but I need to use a wildcard as the middle part of the file name, the date, changes from time to time.

Any suggestions would be greatly appreciated. 
 
#python script by bob 5.17.06
#calls ftplib module & time module
#access qpublic ftp, download 

import win32com.client
import ftplib
import os
import time


gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
dir = 'Q:/Data/temp'
gp.Workspace = dir

fname = "Parcels_" + time.strftime("%m%d%y")

gp.CreateFolder_management(gp.Workspace, fname)
ftp = ftplib.FTP("www.data.com")
ftp.login("yoe@data.com", "xxxxx")
ftp.retrlines('LIST')
#Line that I can't figure out? 
ftp.retrbinary('RETR JAX_may09.tar.gz', open(dir + "\\" + fname + "\\" + "JAX_may09.tar.gz", 'wb').write)
                                            
print ftp.dir()

#ftp.quit()
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: ftp file retrieval using wildcard 
Author Petr K. 
Date Jun 14, 2006 
Message Hi Robert,

you'll need to get the list of all files in the directory and then check for those which match your pattern. The fnmatch() function is very suitable for doing the pattern-checking, try having a look at it.

Hope that helps,
Petr Krebs
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: ftp file retrieval using wildcard 
Author Robert Ehrman 
Date Jun 15, 2006 
Message Great suggestion. It works great. Thanks for your help.