I’m hoping someone can point me in the right direction as I’m banging my head against a wall...
I’m trying to use an NSTask to rsync from a remote server, but authenticating with an ssh key by specifying the -e ‘ssh -i /path/to/ssh/key’ option. I’m having a hard time figuring out the format to put that into the NSTask args array...
In the shell, the command I’m trying to run would look like the following (note the quotes around the ssh portion):
rsync -e 'ssh -i “/path/to/ssh/private/key"' -avzp --delete --progress email@hidden:/Path/To/Master/Folder/ /Path/To/Destination/Folder
What I have is something like this:
set certPath to current application's NSBundle's mainBundle()'s pathForResource:”certname" ofType:""
tell current application's NSTask to set theTask to alloc()'s init()
set sshOption to ("'ssh -i \"" & (certPath as text) & "\"'")
set options to {"-e", sshOption, "-avzp", "--delete", "--progress", "email@hidden:/Path/To/Master/Folder/", "/Path/To/Destination/Folder"}
tell theTask
its setLaunchPath:"/usr/bin/rsync"
its setArguments:options
its setStandardOutput:outPipe
its setStandardError:outPipe
end tell
When I try to run this, I get the following logged as my ‘options’:
(
"-e",
"'ssh -i \"/Users/myuser/Library/Developer/Xcode/DerivedData/Casper_9_Sync-fjpqyxbfxqyoanhgjopdedfopidj/Build/Products/Debug/Casper 9 Sync.app/Contents/Resources/certname\"'",
"-avzp",
"--delete",
"--progress",
“/Path/To/Destination/Folder”
)
And then the following error:
rsync: Failed to exec ssh -i "/Users/myuser/Library/Developer/Xcode/DerivedData/Casper_9_Sync-fjpqyxbfxqyoanhgjopdedfopidj/Build/Products/Debug/Casper 9 Sync.app/Contents/Resources/certname": No such file or directory (2)
rsync error: error in IPC code (code 14) at /SourceCache/rsync/rsync-42/rsync/pipe.c(86) [receiver=2.6.9]
2014-08-05 15:19:32.885 Casper 9 Sync[35829:303] rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [receiver=2.6.9]
I did verify that that certfile is embedded into the /Contents/Resources/ folder of the App bundle, which matches the path logged, so the “No such file or directory” message has me a bit stumped… Perhaps the certPath containing spaces is causing problems and needs to be quoted?
I’ve tried specifying the ssh option in several different ways but just doesn’t seem to be working for me. I have to confess, while I understand the array of options, I’m not quite sure how to specify an option when it contains several parameters that need to be wrapped in quotes like this.
I’ve also tried to break up each part of the flag into a separate parameter, i.e.:
set options
to {
"-e", “ssh”, “-i”, certPath,
"-avzp",
"--delete",
"--progress",
"email@hidden:/Path/To/Master/Folder/",
"/Path/To/Destination/Folder"}
Thanks in advance for any advice / assistance offered.
Jeff