POST
|
Hi all you Pythoners, I am fairly new to this , but using online resources I have put together a script that fetches one file from an ftp connection (Python 2.5 on windows xp). I would like to download all the files within a specific directory but I am having trouble with the syntax of for/batch/iteration loop. This is what I have so far: ----------------------------------------------------------------------------------------------- # Import the FTP object from ftplib from ftplib import FTP import os, sys # This will handle the data being downloaded def handleDownload(block): file.write(block) print ".", # Create an instance of the FTP object # FTP('hostname', 'username', 'password') ddir='C:\\GISData\\test\\' os.chdir(ddir) ftp = FTP('ftptest.int') # Log in to the server print 'Logging in.' # You can specify username and password here : ftp.login('user1', 'testpassword') # This is the directory that we want to go to directory = '\\GIS\\test\\datatest' # Change to that directory. print 'Changing to ' + directory ftp.cwd(directory) # Print the contents of the directory ftp.retrlines('LIST') # file name to acquire. filename = 'boundary.shp' #for file in directory: # Open the file for writing in binary mode print 'Opening local file ' + filename file = open(filename, 'wb') # Download the file a chunk at a time # Each chunk is sent to handleDownload # We append the chunk to the file and then print a '.' for progress # RETR is an FTP command print 'Getting ' + filename ftp.retrbinary('RETR ' + filename, handleDownload) # Clean up print 'Closing file ' + filename file.close() print 'Closing FTP connection' ftp.close() ---------------------------------------------------------------------------------------------- Any suggestions? Thanks!
... View more
03-01-2011
04:44 AM
|
0
|
1
|
5266
|
POST
|
Hi all, I am working on a python script that copies tiffs while forcing conversion to RBG (running ArcEditor 9.3.1 no SA extension) Being a newbee in Python, the script does not work and not too keen on using the Batch of Copy Raster under DManagement. Any ideas about what's wrong with the script will be appreciated! import arcgisscripting, sys, os gp = arcgisscripting.create(9.3) gp.Overwriteoutput = 1 # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") #workspace gp.workspace = "C:\GISData\ESRI_Data\test" #List all features in gp.workspace rasters = gp.ListRasters("*") for raster in rasters: gp.CopyRaster(raster,"C:\ESRI_Data\test\output\output.gdb","#","0","#","NONE",ColormapToRGB,"#") print raster + " is converted." Thanks in advance for any suggestions.
... View more
02-15-2011
01:30 AM
|
0
|
0
|
235
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|