Python Forum
How to access files from shared folder?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access files from shared folder?
#1
I am trying to connect share folder using python but not able to connect
bellow is my code:
    from pathlib import Path
    data_folder = Path("//xx.xx.xx.xx//d$//ftpAutoLogin//jflow-data-files-poc")
    file_to_open = data_folder / "mscreen_gxml20200522-143205-512.xml"
    f = open(file_to_open)
    print(f.read())
Error:
Traceback (most recent call last): File "/Users/sam1546/Documents/jflow_ebm_data_extraction/ebm_extractor_sharepath.py", line 19, in <module> f = open(file_to_open) FileNotFoundError: [Errno 2] No such file or directory: '//xx.xx.xx.xx/d$/ftpAutoLogin/jflow-data-files- poc/mscreen_gxml20200522-143205-512.xml' Process finished with exit code 1
Reply
#2
Your procedure looks okay, and works fine on my windows machine with different filenames given.

Try a shorter path, make sure the filenames are really correct.

What do you get from..
import os
print(os.listdir("//xx.xx.xx.xx/d$")) # just validate we can read the top share directory
Reply
#3
@bowlofred -
I tried with below code on mac machine but no luck -

import os
print(os.listdir("//10.11.12.62/d$"))
to give you more insides on it, i have share folder on server //10.11.12.62/d$ and i am trying to access files from this location.

thanks in advanec
Reply
#4
//xx.xx.xx.xx//d$//ftpAutoLogin//jflow-data-files-poc is not a path on a regular file system, it's a network resource with a different protocol.

Just mount the samba share as drive letter and then you can use regular file system operations like open or os.listdir().

If you want to use the samba protocol directly, you have to look for smbprotocol on PyPi or similar packages.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
@DeaD_EyE - You are great... able to resolve this issue using https://pypi.org/project/smbprotocol/ ,Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 466 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Rename files in a folder named using windows explorer hitoxman 3 693 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Rename all files in a folder hitoxman 9 1,385 Jun-30-2023, 12:19 AM
Last Post: Pedroski55
  How to loop through all excel files and sheets in folder jadelola 1 4,331 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  python gzip all files from a folder mg24 3 3,812 Oct-28-2022, 03:59 PM
Last Post: mg24
  delete all files and subdirectory from a main folder mg24 7 1,529 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  Merge all json files in folder after filtering deneme2 10 2,253 Sep-18-2022, 10:32 AM
Last Post: deneme2
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,092 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 5,879 Jan-07-2022, 04:55 PM
Last Post: bowlofred
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,390 Dec-18-2021, 09:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020