Summary
Creates an ArcGIS Server connection file that can be used to access an ArcGIS Server site.
Discussion
When you create an ArcGIS Server connection and the ArcGIS Serversite is federated with an ArcGIS Enterprise deployment, you must sign in using the ArcGIS Enterprise portal. You can do this using the SignInToPortal function. For these sites, you can only create a connection that uses the site's content.
When you create an ArcGIS Server connection and the ArcGIS Serversite is a stand-alone deployment, a user-level connection is created by default. You can optionally request for the connection file to have an elevated connection to support publishing services. This request will only be honored if the connected user has sufficient privileges to allow the elevated connection.
Different options are available to control access to an ArcGIS Server site's content. If the site has been configured to use a built-in identity store and anonymous access is not allowed, a username and password are required. The person creating the connection file must consider its intended use to properly account for how credentials will be stored and how the file will be used as follows:
- By default, no credentials will be permanently stored in the new connection file because this is the most secure option. When no credentials are saved, a script using the file must manage signing in to the ArcGIS Server site to avoid having the sign-in dialog box appear when the script runs. A script can import credentials from another ArcGIS Server connection file using the ImportCredentials function.
- If the file will be used by scripts that support automated publishing operations, it is useful to store credentials in the connection file, but caution must be taken to keep the script and file secure since publishing operations require elevated privileges. Different elevated credentials may be needed for publishing different services.
- If the file will be used to access services and add them to a map, it is important to understand that the mapping system will first leverage a connection to the ArcGIS Server site that is already established. If no connection is available in memory, the mapping system only leverages credentials stored in the Windows Credential Manager in the user's profile to establish a new connection. If credentials are not available from the Windows Credential Manager, the user who opened the map must sign in.
Once an ArcGIS Server connection file has been created with suitable privileges, you can upload a service definition file using the UploadServiceDefinition function.
Syntax
CreateAGSServerConnection (ags_file_path, server_url, {username}, {password}, {save_credentials_to_wcm}, {save_credentials_to_file}, connection_type)| Parameter | Explanation | Data Type |
ags_file_path | The folder path where the output ArcGIS Server connection file (.ags) will be stored and the name of the file that will be created. The file extension must be .ags. | String |
server_url | The URL of the ArcGIS Server site. You must specify the server URL according to the site requirements. ArcGIS Proonly supports HTTPS connections to ArcGIS Serverdeployments. | String |
username | The username that will be used for ArcGIS Server authentication if the ArcGIS Server site is a stand-alone deployment and has been configured to use a built-in identity store; a username is required in this configuration if anonymous access is not allowed. In all other configurations, provided credentials are ignored and will not be saved. When the ArcGIS Serversite is federated with an ArcGIS Enterprise deployment, you must sign in using the ArcGIS Enterprise portal. | String |
password | The password that will be used for ArcGIS Server authentication if the ArcGIS Server site is a stand-alone deployment and has been configured to use a built-in identity store; a password is required in this configuration if anonymous access is not allowed. In all other configurations, credentials are ignored and will not be saved. When the ArcGIS Server site is federated with an ArcGIS Enterprise deployment, you must sign in using the ArcGIS Enterprise portal. | String |
save_credentials_to_wcm | Specifies whether the username and password for ArcGIS Server authentication will be stored in the WindowsCredential Manager, which is part of the computer's operating system. The ArcGIS Pro mapping system only uses credentials stored in the Windows Credential Manager to sign in to the ArcGIS Server site, access its content, and draw data, because this storage mechanism is secure. If an operation is performed or a script is run on a different machine using the same connection file, the required credentials may not be available because a sign in has not yet occurred on that computer. A sign-in dialog box may appear.
(The default value is False) | Boolean |
save_credentials_to_file | Specifies whether the username and password for ArcGIS Server authentication will be stored in the ArcGIS Serverconnection file (.ags). Python scripts can use the SignInToPortal function to access a federated server's content. For a stand-alone ArcGIS Server site, a script run on a Linux machine will not have access to the Windows Credential Manager to sign in and access the site's content. Use an encrypted login in your script; this option is more secure. Credentials can also be stored in the connection file; this option is less secure.
(The default value is False) | Boolean |
connection_type | Specifies the connection type that will be created to use or publish content on an ArcGIS Server site. When the ArcGIS Server site is federated with an ArcGIS Enterprise deployment, you can only create a connection to use the site's content. When the ArcGIS Server site is a stand-alone deployment, and you have sufficient privileges, the connection is created with the requested elevated connection type.
(The default value is USE_ SERVICES) | String |
| Data Type | Explanation |
| String | The full path of the ArcGIS Server connection file. |
Code sample
Create an ArcGIS Server connection file to anonymously access services from any ArcGIS Server site. The site can either be federated with an ArcGIS Enterprise portal or it can be a stand-alone deployment.
import arcpy
agsFileName = arcpy.CreateAGSServerConnection(
r"C:\Project\MyOrganization.ags",
"https://organization.example.com/server")Create an ArcGIS Server connection file that can be used to publish services to a stand-alone deployment of ArcGIS Server.
import arcpy
12345678901234567890123456789012345678901234567890123456789012345678901234567890
agsFileName = arcpy.CreateAGSServerConnection(
r"C:\Project\MyServer.ags",
"https://organization.example.com/arcgis",
"MyUserName",
"MyPassword",
False,
True,
"PUBLISH_SERVICES")