Here is the file, which isn't working right now:
[perl]
#!/usr/bin/perl
use strict;
use Net::FTP;
#declare global login etc variables
my $login;
my $password;
my $basepath;
my $file;
my $datadir;
my $dot1;
my $dot2;
my $server;
my $path;
my $mkd;
my $f;
my $ftp;
my $filename;
my @site;
my $fileinsite;
my $initial;
#my $filename;
#my $mkd;
$login = "";
$password = "";
$server = "";
$basepath = "/path/to/site";
$datadir = "practice";
$initial = "testing";
$f = "";
$filename = "";
$mkd = "";
opendir(THEDIR, "$datadir") ¦¦ die ("Could not open the datadir: $datadir");
@site = readdir(THEDIR);
closedir(THEDIR);
$dot1 = shift(@site);
$dot2 = shift(@site);
($ftp, $server, $login, $path, $initial, $f, @site, $filename, $mkd) = (" ", "", "", "",
"testing", "", "@site", "", "")
if ( my($ftp) = Net::FTP->new("$server") ) {
print "Connected to $server\n";
if ($ftp->login("$login","$password")) {
print "Logged into $server\n";
$ftp->cwd("$path/");
$ftp->mkdir("$initial");
$ftp->cwd("$initial");
foreach $f (@site) {
#chomp($f);
#print "@site\n";
print "$f\n\n";
$filename = $f;
$f =~ s/\.html//g;
print "dir will be $f";
$mkd = $ftp->mkdir("$f");
if ($mkd) {
print "ok\n";
print "dir is $f";
}
else {
print "failed\n $f\n";
print "exiting...\n";
exit(0); }
$ftp->cwd("$f");
$ftp->put("practice/$filename");
$ftp->cwd("$initial");
}
}
else {
print "Cannot connect to $server!\n";
$ftp->quit();
return 0;
}
print "Done...\n";
}
1;
[/perl]
Any help greatly appreciated...
if this software will do you any good, here's a working version:
what it does: reads the names of all files in a directory, and then uploads them to a server, within a directory that is the same as the file name, for example it will connect to a server, make a directory called 'pagename' and then put 'pagename.html' in that directory.
However, that's about all the explanation I'm going to give. Turns out, the script does work with strict after all :)
here goes:
[perl]
#!/usr/bin/perl
#use strict;
use Net::FTP;
#declare global login etc variables
my $login;
my $password;
my $basepath;
my $file;
my $datadir;
my $dot1;
my $dot2;
my $server;
my $path;
my $mkd;
my $f;
my $ftp;
my $filename;
my @site;
my $fileinsite;
my $initial;
#my $filename;
#my $mkd;
$login = "";
$password = "";
$server = "";
$basepath = "";
$datadir = "practice";
$initial = "testing";
$f = "";
$filename = "";
$mkd = "";
opendir(THEDIR, "$datadir") ¦¦ die ("Could not open the datadir: $datadir");
@site = readdir(THEDIR);
closedir(THEDIR);
$dot1 = shift(@site);
$dot2 = shift(@site);
if (my($ftp) = Net::FTP->new("$server")) {
print "Connected to $server\n";
if ($ftp->login("$login","$password")) {
print "Logged into $server\n";
$ftp->cwd("$path/");
$ftp->mkdir("$initial");
$ftp->cwd("$initial");
foreach $f (@site) {
#print "$f\n\n";
$filename = $f;
$f =~ s/\.html//g;
print "dir will be $f\n";
$mkd = $ftp->mkdir("$f");
print "ok\n";
print "dir is $f\n";
$ftp->cwd("$f");
$ftp->put("practice/$filename");
#$ftp->cwd("$initial");
$ftp->cwd("..");
sleep(2);
}
}
else {
print "Cannot connect to $server!\n";
$ftp->quit();
return 0;
}
print "Done...\n";
}
1;
[/perl]