• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mounting AFP Volume using Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mounting AFP Volume using Cocoa


  • Subject: Re: Mounting AFP Volume using Cocoa
  • From: Bill Monk <email@hidden>
  • Date: Fri, 18 Apr 2008 14:48:54 -0500

On Apr 18, 2008, at 2:03 PM, Jens Alfke <email@hidden> wrote:

I haven't used any of those functions. How about reading the
documentation? Just type "FSVolumeMount" into Xcode's documentation
viewer.

Well, um, that won't help him much, because there is no such function.


Something like this will do the job:


-(OSStatus)mountServer:(NSString *)serverAddress volumeName:(NSString *)volumeName usingTransport:(NSString *)transportName optionalMountDirectory:(NSString *)mountDirectoryPath username:(NSString *)userName passsword:(NSString *)password returnRefNum:(FSVolumeRefNum *)returnRefNum {


// encode afp:// URL for server, without userName/password
NSString *urlStringOfVolumeToMount = [NSString stringWithFormat:@"%@://%@/%@", transportName, serverAddress, volumeName];

// make sure any space characters in the url string are percent- escaped
urlStringOfVolumeToMount = [urlStringOfVolumeToMount stringByAddingPercentEscapesUsingEncoding:NSMacOSRomanStringEncoding];


NSURL *urlOfVolumeToMount = [NSURL URLWithString:urlStringOfVolumeToMount];

// create NSURL for optional mount directory on server - left as an exercise for the reader

// To mount a volume quietly, without an authentication dialog, it's necessary that FSMountServerVolumeSync's
// userName and password params not be NULL.
// If they are encoded into the URL, and the server doesn't exist, passing NULL for these params
// causes the system to put up a "server is not available or may not be operational" dialog.
//
// The solution is to always pass userName and password directly to FSMountServerVolumeSync, and leave them
// out of the URL.
// This will mount the volume if it's possible, and if not, quietly return an error, and no authentication
// dialog will appear (assuming the name/password are valid, of course).
OSStatus error;
error = FSMountServerVolumeSync( (CFURLRef)urlOfVolumeToMount,
NULL, //(CFURLRef)mountDirectoryPath, // if NULL, default location is mounted.
(CFStringRef)userName,
(CFStringRef)password,
returnRefNum,
0L /* OptionBits, currently unused */ );


if ( error ) {
NSBeep();
NSLog( @"Server %@/%@ reported error %d", serverAddress, volumeName, error );
}


	return error;
}


and used something like:

FSVolumeRefNum refNum;
OSStatus status;

err = [self  mountServer:@"MyServer.local"
	      volumeName:@"volumeName"
	  usingTransport:@"afp"
 optionalMountDirectory:@""
                username:@"username"
               passsword:@"password"
            returnRefNum:&refNum];

err = [self mountServer:@"idisk.mac.com"
volumeName:@"youriDisk-Public"
usingTransport:@"http"
optionalMountDirectory:@""
username:@"username"
passsword:@"" // assuming the iDisk has no password set on /Public
returnRefNum:&refNum];


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Mounting AFP Volume using Cocoa
      • From: JanakiRam <email@hidden>
  • Prev by Date: Re: running out of NSPipes
  • Next by Date: Modal popup from command line tool or daemon?
  • Previous by thread: Re: Mounting AFP Volume using Cocoa
  • Next by thread: Re: Mounting AFP Volume using Cocoa
  • Index(es):
    • Date
    • Thread