{"id":2893,"date":"2026-02-10T08:13:55","date_gmt":"2026-02-10T07:13:55","guid":{"rendered":"https:\/\/artheodoc.fr\/?p=2893"},"modified":"2026-02-10T08:13:55","modified_gmt":"2026-02-10T07:13:55","slug":"code-en-python-sous-linux-pour-telecharger-un-fichier-qui-se-trouve-sur-un-serveur-nextcloud","status":"publish","type":"post","link":"https:\/\/artheodoc.fr\/index.php\/2026\/02\/10\/code-en-python-sous-linux-pour-telecharger-un-fichier-qui-se-trouve-sur-un-serveur-nextcloud\/","title":{"rendered":"Code en Python sous Linux pour t\u00e9l\u00e9charger un fichier qui se trouve sur un serveur Nextcloud"},"content":{"rendered":"\n<p>Test\u00e9 sous Linux Mint &#8211; Version de Python&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">python3 --version<br>Python 3.12.3<\/pre>\n\n\n\n<p>V\u00e9rifier si la librairie requests est install\u00e9e&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dpkg -l python3-requests<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Souhait=inconnU\/Install\u00e9\/suppRim\u00e9\/Purg\u00e9\/H=\u00e0 garder<br>| \u00c9tat=Non\/Install\u00e9\/fichier-Config\/d\u00e9paqUet\u00e9\/\u00e9chec-conFig\/H=semi-install\u00e9\/W=attend-traitement-d\u00e9clenchements<br>|\/ Err?=(aucune)\/besoin R\u00e9installation (\u00c9tat,Err: majuscule=mauvais)<br>||\/ Nom              Version                Architecture Description<br>+++-================-======================-============-===================================================================<br>ii  python3-requests 2.31.0+dfsg-1ubuntu1.1 all          elegant and simple HTTP library for Python3, built for human beings<\/pre>\n\n\n\n<p>Exemple de code en Python pour t\u00e9l\u00e9charger un fichier se trouvant sur un serveur Nextcloud.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/env python3.12<br># -- coding: utf-8 --<br><br>import requests<br>from requests.auth import HTTPBasicAuth<br><br># Remplacez ces valeurs par les v\u00f4tres<br>nextcloud_url = \"https:\/\/votre-serveur-nextcloud.com\"<br>username = \"votre_utilisateur\"<br>password = \"votre_mot_de_passe\"  # ou utilisez un token d'application<br>remote_file_path = \"\/chemin\/vers\/le\/fichier\/sur\/nextcloud\/fichier.txt\"<br>local_file_path = \"\/chemin\/local\/vers\/fichier.txt\"<br><br># Construction de l'URL pour t\u00e9l\u00e9charger le fichier<br>download_url = f\"{nextcloud_url}\/remote.php\/dav\/files\/{username}{remote_file_path}\"<br><br># T\u00e9l\u00e9chargement du fichier<br>response = requests.get(<br>    download_url,<br>    auth=HTTPBasicAuth(username, password),<br>    verify=True  # D\u00e9sactivez si vous utilisez un certificat auto-sign\u00e9<br>)<br><br># V\u00e9rification de la r\u00e9ponse<br>if response.status_code == 200:<br>    with open(local_file_path, 'wb') as f:<br>        f.write(response.content)<br>    print(f\"Fichier t\u00e9l\u00e9charg\u00e9 avec succ\u00e8s\u00a0: {local_file_path}\")<br>else:<br>    print(f\"Erreur lors du t\u00e9l\u00e9chargement\u00a0: {response.status_code} - {response.text}\")<\/pre>\n\n\n\n<p>Dans mon cas le dossier <strong>Documentation_Dominique<\/strong> est visible dans mon interface Nextcloud, le param\u00e8tre <strong>remote_file_path<\/strong> est de ce type \u00ab\u00a0\/Documentation_Dominique\/dossier\/fichier.txt\u00a0\u00bb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test\u00e9 sous Linux Mint &#8211; Version de Python&nbsp;: python3 &#8211;versionPython 3.12.3 V\u00e9rifier si la librairie requests est install\u00e9e&nbsp;: dpkg -l python3-requests Souhait=inconnU\/Install\u00e9\/suppRim\u00e9\/Purg\u00e9\/H=\u00e0 garder| \u00c9tat=Non\/Install\u00e9\/fichier-Config\/d\u00e9paqUet\u00e9\/\u00e9chec-conFig\/H=semi-install\u00e9\/W=attend-traitement-d\u00e9clenchements|\/ Err?=(aucune)\/besoin R\u00e9installation (\u00c9tat,Err: majuscule=mauvais)||\/ Nom Version Architecture Description+++-================-======================-============-===================================================================ii python3-requests 2.31.0+dfsg-1ubuntu1.1 all elegant and simple HTTP library for Python3, built for human beings Exemple de code en Python pour t\u00e9l\u00e9charger un fichier [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17,30],"tags":[18,31],"class_list":["post-2893","post","type-post","status-publish","format-standard","hentry","category-nextcloud","category-python","tag-nextcloud","tag-python"],"_links":{"self":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/posts\/2893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/comments?post=2893"}],"version-history":[{"count":1,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/posts\/2893\/revisions"}],"predecessor-version":[{"id":2894,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/posts\/2893\/revisions\/2894"}],"wp:attachment":[{"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/media?parent=2893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/categories?post=2893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artheodoc.fr\/index.php\/wp-json\/wp\/v2\/tags?post=2893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}