Click to See Complete Forum and Search --> : trouble moving files across devices


leedo
07-12-2003, 07:59 PM
I'm writing a script that allows the user to move files from one directory to another from a web interface. I keep getting this error from perl.
Invalid cross-device link
Is this because the destination is on a different drive? Any idea's on why perl would give me this error?

Jeff Mott
07-12-2003, 09:59 PM
Invalid cross-device link is actually an error returned from Linux rather than perl. It also may be that your Web host has created a virtual root, preventing you (or programs executed under your account) access to the rest of the file system. But this is all speculation. I really can't tell very much unless I can see the program.

leedo
07-12-2003, 11:02 PM
Thanks for the reply. I've been doing a bit of research on usenet, and have tried a few different things. Here is the current state of what I am working on.

#!usr/bin/perl -wT

%simple_form = undef;
&parse_form_data (*simple_form);
my $download = "/ftp/users/download";
my $permanent = "/ftp/permanent";

foreach $dir ( sort keys %simple_form) {
$dir =~ tr/+/ /;
$dir = ~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$source = "$download/$dir";
$target = "$permanent/$dir";

system("cp -R $target");
print "Couldn't copy($?): $!\n" if $?;
}
This isn't working... I'm not sure if it is a permission problem or what. all the folders in '/ftp' are owned by the same user:group so I don't see how it could be permission problems.

Is it possible that any spaces in the $taget path could be causing problems?

edit: It's definitly the spaces in the directory names. Any help you can give on how to insert a "\" before the spaces would be awesome. I'm having trouble doing it with s///.

leedo
07-12-2003, 11:57 PM
Well, I got it working 90% of the time. Some folders don't seem to copy over. But I don't notice anything different about their path names.

For example.
Moving
/ftp/users/download/The\ Mountain\ Goats\ -\ Live\ at\ Macrock
to
/ftp/permanent/The\ Mountain\ Goats\ -\ Live\ at\ Macrock
creates the directory, but doesn't copy over the files. This isn't a huge deal, as the script is only being used by me. But I have no idea why it doesn't work.

joslin
09-26-2005, 08:31 AM
edit: It's definitly the spaces in the directory names. Any help you can give on how to insert a "\" before the spaces would be awesome. I'm having trouble doing it with s///.

# should put a \ escapesign before a space, tab, newline ... haven't tested it though :o
$dir =~ s/(\s)/\\$1/g;

bu maybe you could remove any spaces ?

$dir =~ s/\s//g;