简体   繁体   中英

Execute SSHFS script in Cocoa OSX

I used this command in Terminal and it can mount the drive successful. Now i want to put this command in Cocoa app to mount the Drive in my Cocoa app but i dont know how to call this. Is there anyway to put this command into the script and call the script? If put the script, we need to input the parameter for it. Pls advise. Thanks much

sshfs -p 12001 abc@host.example.com:/host/root testSSHFS

UPDATE:

I tried the below code but i got error but when I tried on Terminal, it can mount the drive successfully.

remote host has disconnected
mount_osxfusefs: failed to mount /Volumes/TEST_DRIVE@/dev/osxfuse4: Socket is not connected

Here is the code i using:

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"/opt/local/bin/sshfs"];
[task setArguments:@[@"-p 12000", @"600252@abc.com:/test", @"/Volumes/TEST_DRIVE",@"-oauto_cache,reconnect,defer_permissions,negative_vncache,noappledouble,volname=TEST_DRIVE"]];

NSPipe *inPipe = [NSPipe pipe];
[task setStandardInput:inPipe];

NSPipe *outPipe = [NSPipe pipe];
[task setStandardOutput:outPipe];

NSFileHandle *writer = [inPipe fileHandleForWriting];
NSFileHandle *reader = [outPipe fileHandleForReading];

[task launch];

//Wait for the password prompt on reader [1]
NSString* password = @"d6b0ab7f1c8ab8f514db9a6d85de160a";
NSData *passwordData = [password dataUsingEncoding:NSUTF8StringEncoding];
[writer writeData:passwordData];

[task waitUntilExit];

Pls advise. thanks

Something like this:

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"sshfs"];
[task setArguments:@[@"-p 12001", @"abc@host.example.com:/host/root", @"testSSHFS"]];

[task launch];
[task waitUntilExit];

I haven't tested this, so think of this as a guide.

You'll probably have to provide the full path to sshfs to -setLaunchPath: . You might have to jigger your arguments too; I don't know if "-p 12001" should be one argument or two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM