简体   繁体   English

在Cocoa OSX中执行SSHFS脚本

[英]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. 现在,我想将此命令放在Cocoa应用程序中,以将驱动器装入我的Cocoa应用程序中,但我不知道该如何调用。 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: . 您可能必须提供sshfs-setLaunchPath:的完整路径。 You might have to jigger your arguments too; 您可能还需要提高自己的论点。 I don't know if "-p 12001" should be one argument or two. 我不知道"-p 12001"应该是一两个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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