gpt4 book ai didi

cocoa - 使用 NSTask 和 rsync 捕获所需的凭据

转载 作者:行者123 更新时间:2023-12-03 16:20:51 26 4
gpt4 key购买 nike

法国开发者的拳头帖子!我正在尝试使用 rsync 和 Objective-C 创建一个简单的同步。所以我像这样使用 NSTask :

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/rsync"];
NSArray* args = [NSArray arrayWithObjects:@"-av", @"/Users/BiB1/Documents/test/", @"login@ftp.myserver.net:~/test/", nil];
NSDictionary* env = [NSDictionary dictionaryWithObject:<#(id)object#> forKey:<#(id)key#>
[task setArguments:args];
NSPipe *outPipe = [[NSPipe alloc] init];
[task setStandardOutput:outPipe];
[outPipe release];
[task launch];

NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile];
[task waitUntilExit];

int status = [task terminationStatus];
[task release];
if(status != 0)
{
NSDictionary *eDict = [NSDictionary dictionaryWithObject:@"Sync impossible" forKey:NSOSStatusErrorDomain];
NSError *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:0 userInfo:eDict];

NSLog(@"EDICT : %@",eDict);
NSLog(@"ERROR : %@",outError);
}

NSString *aString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[self.textField setStringValue:aString];

[aString release];

在终端中,该命令工作正常,但我需要密码。而在 NSTask 中我没有这个请求。

所以我的问题是,有一种方法可以捕获所需的凭据,或者是否可以将密码设置为参数或其他内容。

提前致谢。

BiB1

最佳答案

来自 rsync man页面:

Some modules on the remote daemon may require authentication.If so, you will receive a passwordprompt when you connect. You can avoid the password prompt by setting theenvironment variableRSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be use-ful when scripting rsync.

WARNING: On some systems environment variables are visible to all users. On those systems using--password-file is recommended.

关于cocoa - 使用 NSTask 和 rsync 捕获所需的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4032596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com