listing network shares with python

后端 未结 5 1223
刺人心
刺人心 2020-12-11 17:40

if I explicitly attempt to list the contents of a shared directory on a remote host using python on a windows machine, the operation succeeds, for example, the following sni

相关标签:
5条回答
  • 2020-12-11 18:20

    Maybe the following script will help you. See http://gallery.technet.microsoft.com/ScriptCenter/en-us/7338e3bd-1f88-4da9-a585-17877fa37e3b

    0 讨论(0)
  • 2020-12-11 18:30

    May be pysmb can help

    0 讨论(0)
  • 2020-12-11 18:32

    I'm sure the OP has forgotten about this question by now, but here's (maybe) an explanation:

    http://www.python.org/doc/faq/windows/#why-does-os-path-isdir-fail-on-nt-shared-directories

    In case anybody else happens along this problem, like I did.

    0 讨论(0)
  • 2020-12-11 18:35

    Sorry. I'm not able to try this as I'm not in a PC. Have you tried:

    os.listdir("\\\\remotehost\\")
    
    0 讨论(0)
  • 2020-12-11 18:38

    For anyone still wondering how to list network shares at the top level on windows, you can use the win32net module:

    import win32net
    shares, _, _ = win32net.NetShareEnum('remotehost',0)
    

    The integer controls the type of information returned but if you just want a list of the shares then 0 will do.

    This works where os.listdir('\\remotehost') fails as '\\remotehost' isn't a real folder although windows can display it like one.

    0 讨论(0)
提交回复
热议问题