Re: Mounting AFP Volume using Cocoa
Re: Mounting AFP Volume using Cocoa
- Subject: Re: Mounting AFP Volume using Cocoa
- From: JanakiRam <email@hidden>
- Date: Mon, 21 Apr 2008 10:06:47 +0530
Hi Bill,
Thanks for your response.
This code works fine , but when i try to mount a single volume/account on
the same server , this code doesn't seem to work for mounting multiple
volumes/accounts.I'm always getting -43 error.If i unmount the earlier
volume/account on the same server then i'm able to mount another volume on
the same server.
Can you please help me to solve this problem.
Thanks,
JanakiRam.
On Sat, Apr 19, 2008 at 1:18 AM, Bill Monk <email@hidden> wrote:
> 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