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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

losing directoy

Status
Not open for further replies.

jcarrott

Programmer
May 28, 2009
130
US
I am now able to develope the list of files, but the code can't find the files in the local directory.

Code:
#!/usr/bin/perl -w

use Net::FTP;

$vName1   = 'D:\Inetpub\ftproot\Invoice\ghxInv.bak';
$dir      = 'D:\Appdata\Invoice';
$host     = 'edmapp';
$username = 'who_dat.org';
$password = '12345';

if (-e $vName1)
{
##    $rc=system("del /Q $vName1");
    $rc=system("cd $dir");

    opendir($dh, $dir) or die "can't opendir $dir: $!";
    @files = readdir($dh);

    $ftp=Net::FTP->new($host, Debug => 0) or die "No connection";
    $ftp->login($username, $password) or die "cannot login", $ftp->message;
    $ftp->cwd(olc_upload_v0j5) or die "can't cwd ", $ftp->message;
    $ftp->binary();
   
    for $file (@files)
    {
        chomp @files;
        next if $file =~ /^\.{1,2}$/;
        print "$file\n";
##        $ftp->put($file) or die "put failed ", $ftp->message;
    }
    $ftp->quit;
    closedir $dh;

}

I have tried using '$dir$file', which lists the directory and then the file, but the "\" is missing so the string is meaningless.

I have '$dir/$file', '$dir\$file, and '$dir\\' and they error with comments about missing operator.

I even tried '$temp=$dir . "\" . $file;'

It complained about run away ".

can anybody help??

Now that I have the list of files, how do I get the FTP command to include the directory path?
 
I found the fix.

I changed

$rc=system("cd $dir");

to

chdir ($dir);

Now it works great, with the help of the experts at this site. I do thank you all for getting me on the correct path.
 
I would think about using the full path as part of the put statement and not rely on where you are in the system path. It will save you a lot of headaches in the future.

I have found that full pathing everything is the way to salvation :D

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top