Guest User

smb_mount_copy_umount example

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