<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export files from file server using URL path in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331625#M68740</link>
    <description>&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import requests

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
with arcpy.da.SearchCursor(fc, ['LINK']) as cursor:
    for row in cursor:
        print("Downloading: " + row[0])
        response = requests.get(row[0])
        outputFile = row[0].split("/")[0]
        with open(dest_path + '\\' + outputFile, 'wb') as f:
            f.write(response.content)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2023 19:47:17 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2023-09-22T19:47:17Z</dc:date>
    <item>
      <title>Export files from file server using URL path</title>
      <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331191#M68726</link>
      <description>&lt;P&gt;I recently wrote this script to download files from a file server using a folder path.&amp;nbsp; For example the "LINK" field has values such as this: "\\wapgis61\Scans\101-005\101-005.pdf".&amp;nbsp; We have recently changed the source data to to reference a virtual directory which uses URL's.&amp;nbsp; For example, the path referenced earlier is accessed with a URL like this: &lt;A href="http://wapgis61/Scans/101-005/101-005.pdf" target="_blank" rel="noopener"&gt;http://wapgis61/Scans/101-005/101-005.pdf&lt;/A&gt; .&amp;nbsp; Does anyone know how to modify this script to extract files that a referenced with a URL instead of a UNC path?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import shutil

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
cursor = arcpy.SearchCursor(fc)
for row in cursor:
    field = "LINK"
    link = (row.getValue(field))
    head, tail = os.path.split(str(link))
    print ("Downloading: " + tail)
    shutil.copy(link, dest_path)

print("Download Complete")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 17:43:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331191#M68726</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2023-09-21T17:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Export files from file server using URL path</title>
      <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331205#M68728</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3932"&gt;@shildebrand&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can use the requests module to do this.&amp;nbsp; Below is an example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests

# Variables
url = 'https://some.server.com/test.pdf'
exportLocation = r'c:\temp\test.pdf'

response = requests.get(url)

with open(exportLocation, 'wb') as f:
    f.write(response.content)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Sep 2023 18:13:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331205#M68728</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2023-09-21T18:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Export files from file server using URL path</title>
      <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331266#M68734</link>
      <description>&lt;P&gt;Thanks Jake!&amp;nbsp; Do you know how to reference the a feature class field that has the URL in it?&amp;nbsp; The script below returns an error showing that the "LINK" field is an invalid URL.&amp;nbsp; I'm guessing I probably have an incorrect syntax?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import requests

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
cursor = arcpy.SearchCursor(fc)
for row in cursor:
    #url format = http://wapgis61/Scans/101-005/101-005.pdf
    url = "LINK"
    print ("Downloading: " + url)
    response = requests.get(url)
    with open(dest_path, 'wb') as f:
        f.write(response.content)
    
print("Download Complete")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shildebrand_0-1695328789347.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/81338iDA60BDAA01795219/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shildebrand_0-1695328789347.png" alt="shildebrand_0-1695328789347.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 20:42:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331266#M68734</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2023-09-21T20:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Export files from file server using URL path</title>
      <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331625#M68740</link>
      <description>&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import requests

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
with arcpy.da.SearchCursor(fc, ['LINK']) as cursor:
    for row in cursor:
        print("Downloading: " + row[0])
        response = requests.get(row[0])
        outputFile = row[0].split("/")[0]
        with open(dest_path + '\\' + outputFile, 'wb') as f:
            f.write(response.content)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 19:47:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1331625#M68740</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2023-09-22T19:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export files from file server using URL path</title>
      <link>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1332040#M68753</link>
      <description>&lt;P&gt;Thanks Jake, with a slight modification to your suggestion, it worked!&amp;nbsp; Just changed the index number to 5 in row 13.&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import requests

fc = arcpy.GetParameterAsText(0)
dest_path = arcpy.GetParameterAsText(1)
print(fc)
cursor = arcpy.SearchCursor(fc)
with arcpy.da.SearchCursor(fc, ['LINK']) as cursor:
    for row in cursor:
        print("Downloading: " + row[0])
        response = requests.get(row[0])
        outputFile = row[0].split("/")[5]
        print(outputFile)
        with open(dest_path + '\\' + outputFile, 'wb') as f:
            print(f)
            f.write(response.content)
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 15:53:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-files-from-file-server-using-url-path/m-p/1332040#M68753</guid>
      <dc:creator>shildebrand</dc:creator>
      <dc:date>2023-09-25T15:53:26Z</dc:date>
    </item>
  </channel>
</rss>

