Mount Network Share

  1. 12 months ago
    Edited 12 months ago by philcebutv

    Hello,

    How do I code on mounting different network share e.g. (AFP).

    Can anyone share. I am stuck on this..

    my xcode is almost complete except that I do not know how to code to mount the shared folder. I have already all the window and coded all the fields but coding the actual mounting is a bit hard. I did not find any sample on the net.

    on applescript this will only be a one liner syntax, given that username, password and server fields are there - mount volume "afp://" & user_name & ":" & pass_word & "@" & server_name

    Thanks.

  2. anyone?

  3. 11 months ago

    niutech

    24 Mar 2016 Administrator
    Edited 11 months ago by niutech

    You can do it like this in Swift, using NetFS:

    func mountShare(serverAddress: String, shareName: String, userName: String, password: String) {
        let fm = NSFileManager.defaultManager()
        let mountPoint = "/Volumes/".stringByAppendingString(shareName)
        var isDir : ObjCBool = false
        if fm.fileExistsAtPath(mountPoint, isDirectory: &isDir) {
            if isDir {
                unmount(mountPoint, 0)
                println("Unmounted: \(mountPoint)")
            }
        }
        let sharePath = NSURL(string: "\(serverAddress)/\(shareName)")!
        let mounted : Int32 = NetFSMountURLSync(sharePath, nil, userName, self.decodeStr(password), nil, nil, nil)
        if mounted > 0 {
            println("Error: sharePath: \(sharePath) Not Valid")
        } else {
            println("Mounted: \(sharePath)")
        }
    }

or Sign Up to reply!