Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP-Script *almost* running

Status
Not open for further replies.

losty25

IS-IT--Management
Jan 26, 2007
4
0
0
LU
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?
 
Ok, wrong interpretation of the error message. Not the delete-thing gives the error, but the try to put an already existing file on the ftp-server.

So the delete-part is absolutely ignored :-(
 
are you trying to delete files on the local computer or on the remote computer?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Why not just either check if it already exists and not upload it or delete the remote file then upload it?
 
That only works for the local file.. I think he is having problems with the remote file already existing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top