0

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

NTNT
  • 541
  • 1
  • 7
  • 18

1 Answers1

1

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.

Extra Savoir-Faire
  • 6,026
  • 4
  • 29
  • 47
  • Thanks but after call the sshfs command, it will need to input the password. Do you know how to set password after calling this command? – NTNT Sep 16 '15 at 15:18
  • Pls. see my updated question. I tried your code but i got some error when mounting. Can you help me to correct? Thanks – NTNT Sep 16 '15 at 16:38
  • As I said, what I posted wasn't tested. I don't have sshfs installed on my system, so I can't go through it with you. But: 1) Did you double-check your arguments? Remember how I said one of them might have to be two arguments? 2) Perhaps there are some environment variables you can set via `-[NSTask setEnvironment:]` in the form of a dictionary, including your credentials. – Extra Savoir-Faire Sep 17 '15 at 03:26
  • Thanks for your response. I find out the issue is it needs ssh_askpass. My new problem is how to run this ssh_askpass. Do you know how to run this? – NTNT Sep 17 '15 at 03:31