【问题标题】:Execute SSHFS script in Cocoa OSX在 Cocoa OSX 中执行 SSHFS 脚本
【发布时间】:2015-09-16 11:43:20
【问题描述】:

我在终端中使用了这个命令,它可以成功安装驱动器。现在我想把这个命令放在 Cocoa 应用程序中以在我的 Cocoa 应用程序中安装驱动器,但我不知道如何调用它。反正有没有把这个命令放到脚本中并调用脚本?如果放置脚本,我们需要为其输入参数。请指示。非常感谢

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

更新:

我尝试了下面的代码,但我得到了错误,但是当我在终端上尝试时,它可以成功安装驱动器。

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

这是我使用的代码:

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];

请指教。谢谢

【问题讨论】:

    标签: objective-c macos bash cocoa sshfs


    【解决方案1】:

    类似这样的:

    NSTask *task = [[NSTask alloc] init];
    
    [task setLaunchPath:@"sshfs"];
    [task setArguments:@[@"-p 12001", @"abc@host.example.com:/host/root", @"testSSHFS"]];
    
    [task launch];
    [task waitUntilExit];
    

    我没有对此进行测试,因此请将此作为指南。

    您可能必须提供从sshfs-setLaunchPath: 的完整路径。你也可能不得不改变你的论点;我不知道"-p 12001" 应该是一个参数还是两个。

    【讨论】:

    • 谢谢,但是调用 sshfs 命令后,需要输入密码。你知道调用这个命令后如何设置密码吗?
    • 请。请参阅我更新的问题。我尝试了您的代码,但安装时出现了一些错误。你能帮我改正吗?谢谢
    • 正如我所说,我发布的内容未经测试。我的系统上没有安装 sshfs,所以我不能和你一起经历。但是:1)您是否仔细检查了您的论点?还记得我说过其中一个可能必须是两个参数吗? 2) 也许您可以通过-[NSTask setEnvironment:] 以字典的形式设置一些环境变量,包括您的凭据。
    • 感谢您的回复。我发现问题是它需要 ssh_askpass。我的新问题是如何运行这个 ssh_askpass。你知道如何运行它吗?
    • 不,但我能找到的最好的文章是:blog.mudflatsoftware.com/blog/2010/01/04/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 2012-05-20
    • 2018-03-19
    • 2015-09-05
    • 1970-01-01
    • 2012-10-06
    相关资源
    最近更新 更多