Hi there,
I got a problem with my little FTP-Script (I replaced the correct servername with server.domain now):
***********
use Net::FTP;
my $host = 'server.domain';
my $sourcedir = 'c:/messdaten';
my $ftp = Net::FTP->new($host,
Timeout => 360,
Port => 21,
Debug => 1,
Hash => 0
);
unless (defined $ftp) {
print "$@\n";
die "Can't create Net::FTP-Object\n";
}
# binary-transfer
$ftp->type("I");
$user = 'MyUser';
$password = 'MyPassword';
$ftp->login($user,$password) || die "Can't login $!";
# Finde alle Dateien im Sourcedir
opendir(DH, $sourcedir) || die "Sourcedir $sourcedir konnte nicht geoeffnet werden: $!";
my @files = readdir DH;
closedir(DH);
# Filtere nur die "richtigen" Datein aus dem Array
foreach my $actfile (@files) {
next if ($actfile =~ /^\.\.?$/); # Ueberspringe . und ..
next if ($actfile !~ /^.+?csv$/); # Ueberspringe falls kein csv File
next if ($actfile =~ /^.+?_all_.+?$/); # Ueberspringe Files mit _all_ im Namen
if ($actfile =~ /^.+?_PT_.+?$/) {
push (@important_PT_files, "$actfile"); next; # extrahiert die Property files
}
push (@importantfiles, "$actfile"); # Der Rest ist alles wichtig
}
$dir = '/MessPC';
$ftp->cwd($dir);
foreach my $actfile (@importantfiles) {
my $sourcefile = "$sourcedir/$actfile";
{$ftp->put($sourcefile);
system("del /Q C:\\Messdaten\\$actfile");
}
}
# Hier werden die Property Dateien in das richtige Verzeichnis verschoben.
$dir = '/ptdir';
$ftp->cwd($dir);
foreach my $actfile (@important_PT_files) {
my $sourcefile = "$sourcedir/$actfile";
{$ftp->put($sourcefile);
system("del /Q c:\\Messdaten\\$actfile");
}
}
$ftp->quit() || die "Fehler beim ausloggen von $server.\n\n"
******************
So far so good, it runs. But at the line system("del /Q c:\\Messdaten\\$actfile"); I get the error 425 Permission denied. File exists.
Don't know exactly what's going wrong, the permissions exist and of course the file has to exist before it can be deleted.
Any clue?
I got a problem with my little FTP-Script (I replaced the correct servername with server.domain now):
***********
use Net::FTP;
my $host = 'server.domain';
my $sourcedir = 'c:/messdaten';
my $ftp = Net::FTP->new($host,
Timeout => 360,
Port => 21,
Debug => 1,
Hash => 0
);
unless (defined $ftp) {
print "$@\n";
die "Can't create Net::FTP-Object\n";
}
# binary-transfer
$ftp->type("I");
$user = 'MyUser';
$password = 'MyPassword';
$ftp->login($user,$password) || die "Can't login $!";
# Finde alle Dateien im Sourcedir
opendir(DH, $sourcedir) || die "Sourcedir $sourcedir konnte nicht geoeffnet werden: $!";
my @files = readdir DH;
closedir(DH);
# Filtere nur die "richtigen" Datein aus dem Array
foreach my $actfile (@files) {
next if ($actfile =~ /^\.\.?$/); # Ueberspringe . und ..
next if ($actfile !~ /^.+?csv$/); # Ueberspringe falls kein csv File
next if ($actfile =~ /^.+?_all_.+?$/); # Ueberspringe Files mit _all_ im Namen
if ($actfile =~ /^.+?_PT_.+?$/) {
push (@important_PT_files, "$actfile"); next; # extrahiert die Property files
}
push (@importantfiles, "$actfile"); # Der Rest ist alles wichtig
}
$dir = '/MessPC';
$ftp->cwd($dir);
foreach my $actfile (@importantfiles) {
my $sourcefile = "$sourcedir/$actfile";
{$ftp->put($sourcefile);
system("del /Q C:\\Messdaten\\$actfile");
}
}
# Hier werden die Property Dateien in das richtige Verzeichnis verschoben.
$dir = '/ptdir';
$ftp->cwd($dir);
foreach my $actfile (@important_PT_files) {
my $sourcefile = "$sourcedir/$actfile";
{$ftp->put($sourcefile);
system("del /Q c:\\Messdaten\\$actfile");
}
}
$ftp->quit() || die "Fehler beim ausloggen von $server.\n\n"
******************
So far so good, it runs. But at the line system("del /Q c:\\Messdaten\\$actfile"); I get the error 425 Permission denied. File exists.
Don't know exactly what's going wrong, the permissions exist and of course the file has to exist before it can be deleted.
Any clue?