Credentials required for NSTask and rsync

Fisting for the French developer! I am trying to create simple synchronization using rsync and objective-c. Therefore, I used NSTask as follows:

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

In the terminal, the command works fine, but I have a password request. And in NSTask I do not have this request.

So my question is, is there a method for catching a critical value, or can I set a password as a parameter or something else.

Thanks in advance.

BiB1

+3
source share
3 answers

on the rsync man page :

. , . , RSYNC_PASSWORD , , -password-file. - rsync.

. . , -.

+1

, - SSH/rsync. rsync:

rsync -azvr --stats --rsh="ssh -p${ssh port} -i /path/to/certificate/key" ${source} ${destination}

:

--rsh="ssh -p${ssh port} -i /path/to/certificate/key"

-i , , "" .

:

ssh-keygen -t rsa -b 2048 -f key

-

script ( script ), ip ssh
(./setup.sh//192.168.1.22 23024)

echo "generate key"
ssh-keygen -t rsa -b 2048 -f key
echo "push key to server"
rsync -avz --rsh="ssh -p$2" key.pub $1:~/.ssh/key.pub
echo "put key in authorized_keys on server"
ssh -p$2 $1 'bash -s' < ../remote.sh

script, , 'remote.sh'

#!/bin/bash

mkdir .ssh
cd .ssh
cat key.pub > authorized_keys

exit

script , rsync .

- , .

key.pub , , .

.ssh - ssh..

, .

0

Source: https://habr.com/ru/post/1771694/


All Articles