title: scp with special characters programmatically
body: <p>I have been searching for this for a while, and can't find a satisfactory answer.</p>
  
  <p>I have a perl script that needs to copy a file from one host to another, essentially</p>
  
  <pre><code>sub copy_file{
      my($from_server, $from_path, $to_server, $to_path, $filename) = @_;
  
      my $from_location = "$from_server:\"\\\"${from_path}${filename}\\\"\"";
      my $to_location = $to_path . $filename;
      $to_location =~ s/\s/\\\\ /g;
      $to_location = "${to_server}:\"\\\"${to_location}\\\"\"";
  
      return system("scp -p $from_location $to_location &gt;/dev/null 2&gt;&amp;1"");
  }
  </code></pre>
  
  <p>The problem is, some of my filenames look like this:</p>
  
  <pre><code>BLAH;BLAH;BLAH.TXT
  Some really nicely named file( With spaces, prentices, &amp;, etc...).xlx
  </code></pre>
  
  <p>I am already handling whitespaces, and the code for that is quite ugly since on each side, the files could be local or remote, and the escaping is different for the from and to part of the scp call.</p>
  
  <p>what I am really looking for is either to somehow to escape all possible special characters or somehow bypass the shell expansion entirely by using POSIX system calls. I am ok with writing a XS Module if need be. </p>
  
  <p>I have the correct keys set up in the .ssh directory
  Also I am not honestly sure which special characters do and don't cause problems. I would like to support all legal filename characters.</p>