Search code examples
objective-cnetwork-programmingsamba

Objective-C: Reach a file on samba url


I have a mapped samba network drive in Finder (for example "smb://192.168.15.119/public/ptest/test.rtf") and would like to copy a file from that drive to my desktop.

Do you guys know how would one go about achieving this? It's not mandatory to connect to that url through the mapped drive, if you have a solution that simply takes that url and copies the file from it, that's totally OK too.

EDIT: Based on Bastian's answer, the solution was to use NSFileManager's copyItemAtPath method with the source path being:

NSString *sourcePathx1 = [NSString stringWithFormat:@"/Volumes/public/ptest/test.rtf"];

Solution

  • when you connect to a network drive finder will mount it to /Volumes ... you can then access the share over this mountpoint.

    If the share is not connected you can connect it by executing

    mount_smbfs //host/share /some/temp/folder
    

    If you want to access the file directly you would need some kind of samba library like http://nicolas.brodu.numerimoire.net/common/programmation/libsmb/archived_site/index.html but I don't know any active one.