Thursday, June 30, 2011

Transfer files to/from NAO from your program

# This all assumes the default setting of username=nao with robot name =nao.
# Reminder to me -- I need to mkdir the recording folder on nao.

I often want to transfer files to and from my NAO from within my program. To do this without it asking for a password, I have to use public keys.


Example usage:
In Python, I can use the os.system() function to run linux commands.

import os
cmd = 'scp nao@nao.local:/home/nao/recording.wav .'
os.system(cmd)

This would copy the recording I made (for example, using the ALAudioDevice API) to the current directory on my Mac (for example).


How to scp from your computer to NAO without a password:  

1. If you don't already have a public key, generate one:
  • In the home directory of your computer, run ssh-keygen
  • Press enter to name it using the default id_rsa.pub
  • Enter some passphrase (at least 5 characters)

2. Copy the public version of the key to your NAO: 
scp ~/.ssh/id_rsa.pub nao@nao.local:~

3. Log into NAO using ssh nao@nao.local

4. Add the public key to NAO's authorized keys list:
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys


Even cooler!

You can do

cmd = 'scp nao.local:/home/nao/recording.wav .'

without needing to specify the username every time (did you notice it was missing?). This is handy if you're already storing IP='nao.local'.

Adding a default username for nao.local host:

Add the following into ~/.ssh/config:
Host nao.local
        User nao

Note that before "User" you need to put a tab.

3 comments:

  1. Is it possible to copy file from nao to computer with scp?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I mean, is scp command is installed in Nao robot?

    ReplyDelete