Python Script: a zip file (“TEST.gbd.zip”) containing a File Geodatabase with feature classes to download over FTP?

1998
3
08-24-2017 01:32 PM
Highlighted
by
Occasional Contributor III

There is a zip file (“TEST.gbd.zip”) containing a File Geodatabase with both feature classes from FTP County and I need it to download. What is the python script for this case? Please advise. Thank you.

For example, I pulled this part of script like this:  but what about zip file?

# List of Other files to download
# Syntax: County file name with extension separated by colon, then
# the FTP Folder name
CountyOtherFiles = {
'pa_parceldata.dat':r'GISdata/Pa_data/',
'pa_parceldata.txt':r'GISdata/Pa_data/',
'pa_legal_ln.dat':r'GISdata/Pa_data/',
'pa_legal_ln.txt':r'GISdata/Pa_data/',
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I am new to python script. I have been researched thru here and having difficult to find a right answer. I have compressed zipfile in FTP WinSCP.

I am trying to extract or unzip in python from FTP Winscp? It has compressed zip file in FTP. I have Winscp connect to FTP. I am not sure what is the right script for this case. I already have script set up that has been created by someone else. Please advise. Thank you.

I tried to use this script but I got an error. 

ZipFile.extractall(path='GISData/Pubshp', members= 'PaFiles.gdb.zip')NameError: name 'ZipFile' is not defined

PythonGeodatabase

Reply
0 Kudos
3 Replies
Highlighted
MVP Esteemed Contributor

Hi Alexis, I received the messages you sent via DM, but DM makes it a bit hard to know if there are any spacing errors in your code. That is why posting the code using the syntax highlighter in geonet is a bit cleaner.  I tried to repair but still have a few errors where there were # comments and it is hard to tell if the comment includes additional lines or not.  For example,  around line 205, a few lines down from the "for shapefiles in shpList", there are some nested try: statements with full comments under each of the tries.  I'm assuming they not supposed to be all comments, but hard to tell for sure. 

So. I'm not sure exactly what you are having problems with. I took a look at the link to the zipfile script for extracting Unzip zip files in folders and subfolders with python - Stack Overflow 

and modified it to extranct from one of my .zip files that contains a fgdb

import zipfile, fnmatch, os
rootPath = r"c:\___temp"
pattern = "*.zip"
for root, dirs, files in os.walk(rootPath):
     for filename in fnmatch.filter(files, pattern):
          print(os.path.join(root, filename))
          zipfile.ZipFile(os.path.join(root, filename)).extractall(os.path.join(root, os.path.splitext(filename)[0]))

and it extracted everything from the file GDB just fine.   Try doing a test run with a copy of the .zip file in a temp folder to see if it extracts with the above code.  You should only need to change the rootPath to the new foldername, and then if you option ArcCatalog, you should be able to copy/paste the code in the Python window. That way you should be able to see what is in the .zip file.

However, the snapshot you sent looks to be an SDE  GDB dataset, not a file GDB.  (hope it is ok I included it here)

So it your issue not being able to get the FTP (I may not be able to help with that), extract the data from the .zip (See above) or you trying to get it into the SDE database (different issue)?  You said you are new to Python and someone else wrote the script.  Did it work for them?  Have you modified it some already?  Keep in mind that python is very picky about indentation and that controls much of the processing flow. 

I would recommend posting your code using https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s...‌ so it retains the spacing.  Leave out any user/pass credentials and/or rename any proprietary data.  That will allow others to come take a look, and so I am not guessing on the indentation.

Hope this will help get things started.

Highlighted
by
Occasional Contributor III

Rebecca,

Someone else has created it and it is working.  This existing python script is already running from FTP shapefile convert to SDE in Database Connection weekly that screenshot SDE GDB. It is working fine. The new part now in FTP is zip file that is compressed.  I need compressed zip file to unzip and get it into SDE as previous screenshot. I will try to use that zip file script you provided and get it back to you. Also, I will add code blocker here when I wipe out some info.  Thank you for your time and assist.

Reply
0 Kudos
Highlighted
by
Occasional Contributor III

I noticed this now. The county did change the GIS format of the data we are getting to update our SDE database for properties.

I need to transform the actual process to work with the new format. How can I automate and import the new data into the SDE? Here is the code blocker below. Please advise. Thanks.

Reply
0 Kudos