Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import NetFS
- func mountShare(serverAddress: String, shareName: String, userName: String, password: String) {
- let fm = FileManager.default
- let mountPoint = "/Volumes/".appendingFormat(shareName)
- var isDir : ObjCBool = false
- if fm.fileExists(atPath: mountPoint, isDirectory: &isDir) {
- if isDir.boolValue {
- unmount(mountPoint, 0)
- print("Unmounted: (mountPoint)")
- }
- }
- let sharePathRaw = "(serverAddress)/(shareName)"
- let sharePathWithPercentEscapes = sharePathRaw.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
- let sharePath = NSURL(string: sharePathWithPercentEscapes!)
- let kNAUIOptionKey = "UIOption"
- let kNAUIOptionNoUI = "NoUI"
- let mount_options = NSMutableDictionary()
- mount_options[kNAUIOptionKey] = kNAUIOptionNoUI
- NetFSMountURLSync(sharePath as CFURL!, nil, userName as CFString!, password as CFString!, mount_options, nil, nil)
- }
- let argCount = CommandLine.argc
- if argCount == 5 {
- let serverUrl = CommandLine.arguments[1]
- let shareName = CommandLine.arguments[2]
- let userName = CommandLine.arguments[3]
- let password = CommandLine.arguments[4]
- mountShare(serverAddress: "(serverUrl)", shareName: "(shareName)", userName: "(userName)", password: "(password)")
- } else {
- print("Wrong number of arguments.")
- }
- mountVolume "afp://my.server.com" "myVolume" "user" "password"
- mountVolume "afp://my.server.com" "myVolumeÅÄÖ" "user" "password"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement