title: how to use nodejs to copy file with spaces and utf8 from remote server
body: <h2>Problem</h2>
  
  <p>I'm trying to build a node app that will compare a local directory with a remote directory, and then copy any new files from the remote directory to the local directory. Unfortunately, many of the files are user generated content, and they contain spaces characters. My current implementation doesn't appear to be escaping the filename strings correctly. <strong>How can I copy these files to my local environment?</strong></p>
  
  <h2>Current Implementation:</h2>
  
  <pre><code>// ...
  function copyRemoteFile(remoteFile, server, localDir) {
      exec = require('child_process').exec;
      remoteFile = remoteFile.replace(/ /g, '\\\\ ');
      exec('scp ' + server + ':/path/to/files/' + remoteFile + ' ' localDir, function(error, stdout, stderr) {
          console.log(error, stdout, stderr);
      });
  });
  // ...
  </code></pre>
  
  <h2>Current Output</h2>
  
  <p>For this input:</p>
  
  <pre><code>copyRemoteFile('Screen Shot 2013-12-04 at 1_00_13 PM.png', 'server', '.');
  </code></pre>
  
  <p>I get this output:</p>
  
  <blockquote>
    <p>{ [Error: Command failed: scp: /path/to/files/Screen: No > such file or directory
    cp: Shot\: No such file or directory
    cp: 2013-12-04\: No such file or directory
    cp: at\: No such file or directory
    cp: 1_00_13\: No such file or directory
    cp: PM.png: No such file or directory
    ] killed: false, code: 1, signal: null } '' 'scp: /path/to/files/Screen: No such file or<br>
    directory\ncp: Shot\: No such file or directory\ncp: 2013-12-04\: No such file or directory\ncp: 
    at\: No such file or directory\ncp: 1_00_13\: No such file or directory\ncp: PM.png: No such file 
    or directory\n'</p>
  </blockquote>