Download features, table rows, and attachments from ArcGIS MapServer and FeatureServer layer resources into a local dataset.
The tool queries matching object IDs first, downloads records in adaptive blocks, creates the output from the first block, and immediately appends each subsequent block. This approach limits memory use and supports large services more reliably than collecting every FeatureSet before writing the output.
- Downloads feature layers and standalone tables.
- Supports ArcGIS MapServer and FeatureServer layer URLs.
- Applies an optional SQL
WHEREclause. - Applies an optional spatial filter and spatial relationship.
- Downloads related attachments to a local folder.
- Supports public, portal-hosted, federated, and standalone ArcGIS Server services.
- Reuses the active ArcGIS Pro portal sign-in token when available.
- Discovers the standalone ArcGIS Server token endpoint from
/rest/info. - Renews an invalid or expired token once for ArcGIS REST errors 498 and 499.
- Reduces the block size automatically when a request URL is too long.
- Preserves partial output and reports progress if a large download fails.
- ArcGIS Pro with its bundled Python environment and
arcpy. - Network access to the ArcGIS REST service.
- HTTPS for protected services is strongly recommended. ArcGIS token generation requires HTTPS.
The current code has been modernized for recent ArcGIS Pro Python environments. Test the toolbox with the specific ArcGIS Pro and ArcGIS Enterprise versions used by your organization before production use.
- Download or clone this repository.
- Keep
Download Service.tbxanddownload_service.pyin the same folder. - In ArcGIS Pro, open the Catalog pane.
- Add a folder connection to the repository folder.
- Expand
Download Service.tbxand run the Download Service tool.
| Parameter | Description |
|---|---|
| Hosted Feature Service | Select for ArcGIS Online or a federated ArcGIS Enterprise service. |
| ArcGIS Server Service | Select for a standalone ArcGIS Server service. |
| Portal/AGOL | Portal connection used by ArcGIS Pro for hosted or federated services. |
| Service URL Layer/Table | Full REST URL of a layer or table, including its numeric layer ID. |
| Where | Optional SQL filter. When empty, the tool uses 1=1. |
| Spatial Filter | Optional feature class or geometry drawn in ArcGIS Pro. |
| Spatial Relationship | Spatial relationship applied to the filter geometry. |
| Username | Optional username for a protected service. |
| Password | Optional password for a protected service. |
| Folder attachments | Optional existing folder where attachments will be saved. |
| Output Feature Class/Table | Destination feature class or table. |
Example layer URLs:
https://gis.example.com/arcgis/rest/services/Planning/Parcels/FeatureServer/0
https://gis.example.com/server/rest/services/Assets/MapServer/3
The URL must point to an individual layer or table, not only to the MapServer or FeatureServer root.
Leave username and password empty. No token is requested.
Select Hosted Feature Service. The tool reuses the active ArcGIS Pro portal token when available. If both username and password are supplied, the tool first calls SignInToPortal() for the selected portal and then retrieves its sign-in token.
Select ArcGIS Server Service and provide both username and password. The tool reads authInfo.tokenServicesUrl from the server's /rest/info resource and sends credentials to the advertised generateToken endpoint using HTTP POST.
Username and password must either both be supplied or both be empty. Credentials and tokens are not written to geoprocessing messages.
If ArcGIS REST returns error 498 or 499, the tool renews the token and retries once. A token error detected while loading a FeatureSet is handled before the adaptive block-size retry, so it is not mistaken for an excessively long request URL.
CHUNK is set to 100 in download_service.py. The initial block size is the lower of CHUNK and the service's maxRecordCount.
Records are requested by object ID. If FeatureSet.load() fails while authentication remains valid, the tool halves the current block size and retries the same object IDs. It continues until the block succeeds or contains only one object ID.
The first successful block creates the output dataset with Merge. Later blocks are written immediately with Append. If a later block fails, the existing output is retained and the tool reports how many records were written.
The spatial filter is optional. Multiple input geometries are combined before the query. An empty spatial filter is ignored. The selected spatial relationship defaults to esriSpatialRelIntersects in the toolbox.
When an attachment folder is selected and the service reports hasAttachments: true, attachments are saved using this naming convention:
<object-id>-<attachment-id>-<original-name>
Invalid Windows filename characters and path components are removed. The object ID and attachment ID prefixes keep filenames unique. A failed attachment is reported as a warning without exposing the service token, and the remaining attachments continue downloading.
Set PROXIES near the beginning of download_service.py when an explicit proxy is required:
PROXIES = {
"http": "http://10.10.1.10:3128",
"https": "http://10.10.1.10:1080",
}REQUEST_TIMEOUT contains the connection and read timeouts in seconds:
REQUEST_TIMEOUT = (10, 120)The tool distinguishes a valid query returning no object IDs from connection failures, HTTP errors, invalid JSON, malformed REST responses, invalid SQL filters, and ArcGIS REST authentication errors. ArcGIS error codes, messages, and details are included when available.
- Coded-value domains and subtypes are not recreated explicitly.
- Related records are not downloaded.
- Output field selection is not configurable; all fields are requested.
- A token renewal can succeed only when ArcGIS Pro still has a valid portal session or standalone server credentials were supplied.
- Full runtime validation requires ArcGIS Pro because
arcpyis not available in standard Python environments.
- Preserve domains and subtypes.
- Download related records.
- Allow output field selection.
- Add automated tests with an
arcpytest double.
Bug reports, feature requests, and contributions are welcome through GitHub Issues.
Licensed under the Apache License 2.0.