views:

40

answers:

2

Hi guys,

Fist post for a french developer! I'm trying to create a simple synchronization using rsync and objective-c. So I used NSTask like that :

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/rsync"];
NSArray* args = [NSArray arrayWithObjects:@"-av", @"/Users/BiB1/Documents/test/", @"[email protected]:~/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];

In the terminal the command work fine but I have a request for the password. And in NSTask I don't have this request.

So my question is, there is a method for catching crendential needed, or is it possible to set password as parameter or something else.

Thanks by advance.

BiB1

A: 

from the rsync man page:

Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable RSYNC_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.

tlindner
this option does not supply a password to a remote shell transport such as ssh; to learn how to do that, consult the remote shell's documentation. When accessing an rsync daemon using a remote shell as the transport, this option only comes into effect after the remote shell finishes its authentication (i.e. if you have also specified a password in the daemon's config file).
Benjamin Frolicher
A: 

Hi,

As far as I know the only way to do this is to create a separate program to supply the password (ie an "Askpass" program) and to set the environment variable SSH_ASKPASS. I've written up a set of instructions on how to do this here

http://www.mudflatsoftware.com/blog/2010/01/wrapping-rsync-or-ssh-in-an-nstask/

and a source code example here.

http://bitbucket.org/iracooke/ssh-nstask

Although the examples are for ssh, they also apply to rsync. I use this myself and it works pretty well although it's somewhat complicated to setup.

Ira Cooke