ssh.py 1.2 KB

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python3
  2. from subprocess import check_output
  3. import argparse
  4. def fs_connect(letter, user, path, _pswd):
  5. return check_output('net use {0}: \\\sshfs\\{1}@deeejas.asuscomm.com{3} /user:{1} {2}'.format(letter, user, _pswd, path), shell=True)
  6. def fs_disconnect(*args):
  7. for letter in args:
  8. check_output('net use {0}: /delete'.format(letter), shell=True)
  9. # return check_output('net use {0}: /delete', shell=True)
  10. # return check_output('net use R: /delete', shell=True)
  11. parser = argparse.ArgumentParser(description='connect to ssh filesysytem')
  12. parser.add_argument('-connect', action='store_const', const=fs_connect, dest='cmd', help='connect to file server')
  13. parser.add_argument('--l', type=str, help='letter where to mount')
  14. parser.add_argument('--u', type=str, help='username')
  15. parser.add_argument('--psw', type=str, help='password for secure connection')
  16. parser.add_argument('--path', type=str, help='path to files', default='')
  17. parser.add_argument('-disconnect', action='store_const', const=fs_disconnect, dest='cmd', help='disconnect the file server')
  18. args = parser.parse_args()
  19. try:
  20. args.cmd(args.l, args.u, args.path, args.psw)
  21. except TypeError:
  22. args.disc(args.l)