in reply to Escaping special characters in filename for Net::SCP

blazar, I've been bitten by various things in non-UN!X filenames SAMBA'd or transferred to UN!X a number of times, and there are two strategies that usually work, though I can't say if they'll solve your current situation:
  1. use "'" . $filename . "'"
  2. use "'./" . $filename . "'"

HTH!
  • Comment on Re: Escaping special characters in filename for Net::SCP

Replies are listed 'Best First'.
Re^2: Escaping special characters in filename for Net::SCP
by blazar (Canon) on Mar 26, 2005 at 08:22 UTC
    I've been bitten by various things in non-UN!X filenames SAMBA'd or transferred to UN!X
    This is not my case, but I'll try what you suggest as well. This must be next week, however.

    Incidentally I "can't" (for a relaxed meaning of "can't", actually) use 2. as I already have absolute paths.

      Bummer. That's the one that usually takes the prize. However, if the other monk's suggestion that your other system is the one (i.e., NTFS) that's choking, you're OOL and will almost certainly need to change the name in one way or another. Suggest that you go ahead and change the name unless you really want to get to the bottom of it and tell us all why it fubars.
Re^2: Escaping special characters in filename for Net::SCP
by blazar (Canon) on Mar 29, 2005 at 09:20 UTC
    $scp->put(quotemeta) yields:
    Couldn't transfer `/real/file->name': \/real\/file\-\>name: No such file or directory
    
    $scp->put(qq|'$_'|) yields:
    Couldn't transfer `/real/file->name': bash: -c: line 1: unexpected EOF while looking for matching `''
    bash: -c: line 2: syntax error: unexpected end of file
    lost connection
    
    D'Oh!
      What a gross mess, blazar. Anything other than something like the following is not worth your time:
      use File::Copy; $basedir='/path/to/files'; $foo = $_; $foo =~ s#/#slash#g; $foo =~ s#->#arrow#g; $fubar = "$basedir/$_"; copy($fubar, "$basedir/$foo"); $scp->put("$basedir/$foo"); system('rm', "$basedir/$foo") && die "Can't remove $foo:$!\n";
      with appropriate my's and stricts as appropriate.
        I must say that in the meantime I've happily switched to Net::SFTP, so no more problems on the practical side of things. Still slightly curious if it would have been possible to do it with Net::SCP and if so, how. Net::SFTP seems a superior solution in any case...