Advertisement
DeaD_EyE

smb_mount_copy_umount example

Feb 12th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from subprocess import call
  2. import shutil
  3. import pathlib
  4.  
  5. NO_WINDOW = 0x08000000
  6.  
  7. def mount_network(share, drive, user=None, password=None):
  8.     mount_cmd = ['net', 'use', drive, share]
  9.     if user:
  10.         mount += ['/user:{}'.format(user), password]
  11.     print(' '.join(mount_cmd))
  12.     return call(mount_cmd, shell=False, creationflags=NO_WINDOW)
  13.  
  14. def umount_network(drive):
  15.     mount_cmd = ['net', 'use', drive, '/DELETE']
  16.     return call(mount_cmd, shell=False, creationflags=NO_WINDOW)
  17.  
  18. share = r'\\ANDRE-GP70-2PE\Downloads'
  19. drive = 'f:'
  20. user = None
  21. password = None
  22. desktop_path = pathlib.Path.home() / 'Desktop'
  23. mount_network(share, drive)
  24. shutil.copy(r'F:\pIqaD.ttf', desktop_path)
  25. umount_network(drive)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement