title: Passing a filename with an apostrophe into scp using python
body: <p>I'm trying to write a python script to copy files from a remote server to a local directory via scp.</p>
  
  <p>Because I'm running this on an OpenELEC distribution (minimal HTPC linux distro, read-only filesystem except for userhome makes it impractical to install python ssh module), I'm doing this ugly and just passing the filename to the scp command via os.system.</p>
  
  <pre><code>SCPCopy = "scp -c blowfish -C user@host:\"" + pipes.quote(file) + "\" /storage/downloads/incoming/"
  SCPCopy = SCPCopy.replace('\n','')
  os.system(SCPCopy)
  </code></pre>
  
  <p>This works, except for filenames containing an apostrophe.</p>
  
  <p>Below is an example of what gets passed to os.system in a file with an apostrophe:</p>
  
  <pre><code>scp -c blowfish -C user@host:"'/media/sdi1/home/data/bob'"'"'s file.avi'" /storage/downloads/incoming/
  </code></pre>
  
  <p>And the error:</p>
  
  <pre><code>sh: -c: line 0: unexpected EOF while looking for matching `''
  sh: -c: line 1: syntax error: unexpected end of file
  </code></pre>
  
  <p>It looks pipes.quote(x) is escaping the apostrophe (as it should), but obviously the syntax is still incorrect. I've experimented ditching pipes.quote(x) and replacing apostrophes with /' but that isn't getting me anywhere either.</p>