Advertisement
Guest User

Untitled

a guest
Nov 6th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import Foundation
  2. import NetFS
  3.  
  4. func mountShare(serverAddress: String, shareName: String, userName: String, password: String) {
  5. let fm = FileManager.default
  6. let mountPoint = "/Volumes/".appendingFormat(shareName)
  7. var isDir : ObjCBool = false
  8. if fm.fileExists(atPath: mountPoint, isDirectory: &isDir) {
  9. if isDir.boolValue {
  10. unmount(mountPoint, 0)
  11. print("Unmounted: (mountPoint)")
  12. }
  13. }
  14. let sharePathRaw = "(serverAddress)/(shareName)"
  15. let sharePathWithPercentEscapes = sharePathRaw.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
  16. let sharePath = NSURL(string: sharePathWithPercentEscapes!)
  17. let kNAUIOptionKey = "UIOption"
  18. let kNAUIOptionNoUI = "NoUI"
  19. let mount_options = NSMutableDictionary()
  20. mount_options[kNAUIOptionKey] = kNAUIOptionNoUI
  21. NetFSMountURLSync(sharePath as CFURL!, nil, userName as CFString!, password as CFString!, mount_options, nil, nil)
  22. }
  23.  
  24. let argCount = CommandLine.argc
  25. if argCount == 5 {
  26. let serverUrl = CommandLine.arguments[1]
  27. let shareName = CommandLine.arguments[2]
  28. let userName = CommandLine.arguments[3]
  29. let password = CommandLine.arguments[4]
  30. mountShare(serverAddress: "(serverUrl)", shareName: "(shareName)", userName: "(userName)", password: "(password)")
  31. } else {
  32. print("Wrong number of arguments.")
  33. }
  34.  
  35. mountVolume "afp://my.server.com" "myVolume" "user" "password"
  36.  
  37. mountVolume "afp://my.server.com" "myVolumeÅÄÖ" "user" "password"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement