Friday, July 25, 2014

Wireless Music Sync with SSH

  For a while now I've been interested in remote access via Secure Shell (SSH).  One of the first cool things I learned to do with SSH was to wirelessly sync music from my local computer (laptop) to a remote device (my phone).  Of course, there are a number of Android apps out there that will do the same thing, but as with all things Linux, its more fun to get "under the hood" and take the DIY approach.
  • Required PC Programs:
    • openssh
    • rsync
  • Next you'll want to install an SSH client to your phone.  I use SSHdroid.
    • Connect your phone to the same WiFi network as your computer.
    • Open the SSHdroid app and press start (upper right corner of the screen). [Note:  SSH connections, in my experience, sap your phone's battery life pretty fast, so plug your phone in or keep a close eye on the battery status]  Once connected, all the relevant information is displayed on your phone's screen.
  • Connecting Devices
    • Then do:  ssh -p [port_number] [user_name]@[ip_address]
      • Port Number:  See Below Note.
      • User Name:  Is probably root unless you've changed it.
      • IP Address:  Is shown on SSHdroid's connection screen.
      • Note:  The default SSH port is 22, but you may wish to change it for security reasons.  Both the port number and root password can be changed in SSHdroid's "options" menu if desired.  On your PC you'll need to modify the firewall settings.
  • Finding Your Music Library
    • The easiest way is to open your phone's music player and observe which folder it is scanning to generate its library.
    • in my case it is:  /storage/sdcard1/Music
    • You'll also need to know where your music is stored on your PC, such as /home/user/Music
  • Putting it Together
    • A quick rundown of rsync syntax looks like this:
      • rsync [options] [path/to/source] [path/to/destination]
      • Learn about trailing slashes
        • rsync /source/ /target
          • copies the contents of /source to the inside /target (e.g. /source/contents = /target/contents)
        • rsync /source /target
          • copies /source inside of /target (e.g. /target/source)
      • For general purpose I use -aAXv but here I use -avz.  However, you change them as you like.
    • Syntax for the Sync:  rsync [options] [path/to/PC/music/] [username]@[ip_address]:[/path/to/phone/music]
      • My Example:  rsync -avz ~/Music/ root@192.168.1.2:/storage/sdcard1/music
    • You'll be asked for your phone's user (root) password, then the file transfer will begin just like a normal rsync procedure.

No comments:

Post a Comment