A script to ease scp for files with odd names

Sep 13, '07 07:30:00AM

Contributed by: coppit

Here's a perl script that will escape filenames and send the files to a remote server using scp. I save it as scp-to-coppit.org in my user's bin folder, and make it executable (chmod a+x scp-to-coppit.org). Then from the command line, I can do this: scp-to-coppit.org File with weird char's.txt. Here's the code:

#!/usr/bin/perl

@ARGV = map { s/'/\\'/g; $_; } @ARGV;
my $files = "'" . join("' '", @ARGV) . "'";
my $results = `/usr/bin/scp -rBq $files dcoppit\@coppit.org:.`;
print "Output: $results" if $results ne '';
[robg adds: I haven't tested this one.]

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070912092341469