S
sunilkumar_1480
I have to create a directory in a FTP server but before I create i
should check for the existance of the directory. If the directory does
exist then I should not create the directory. The following is the
code which I have written and I am unsuccessful with reading a
directory in a server
my $dir_name = $ARGV[0];
my $basepath = "c:\\Inetpub\\wwwroot\\$dir_name\\test";
my $count = 0;
my $server="casr.com";
my $user="slb";
my $password="bigfiles";
my $dir="iDistrict/incoming/baselines/TestReports/";
my $success="true";
my $filetran="true";
my $reason;
my $test="true";
my @file_list;
my $ret;
my $ftp=Net::FTP->new($server) or $success="false";
$ftp->login($user, $password) or $success="false";
$ftp->pasv() or $success="false";
$ftp->binary() or $success="false";
$ftp->cwd($dir) or $success='false';
print $ftp->cwd($dir);
# I am unable to open the directory that exists in the server which I
have
# mentioned with $dir name.
opendir(SRC, $dir);
my @dir_files = readdir(SRC);
foreach my $file (@dir_files)
{
if($file eq $dir_name)
{
$ret = 0;
closedir(SRC);
last;
}
}
if($ret ne 0)
{
$ftp->mkdir($folder_name) or $success='false';
}
$ftp->cwd($dir."/".$folder_name) or $success='false';
Can anybody help me how to read the contents of a directory in the
server.
should check for the existance of the directory. If the directory does
exist then I should not create the directory. The following is the
code which I have written and I am unsuccessful with reading a
directory in a server
my $dir_name = $ARGV[0];
my $basepath = "c:\\Inetpub\\wwwroot\\$dir_name\\test";
my $count = 0;
my $server="casr.com";
my $user="slb";
my $password="bigfiles";
my $dir="iDistrict/incoming/baselines/TestReports/";
my $success="true";
my $filetran="true";
my $reason;
my $test="true";
my @file_list;
my $ret;
my $ftp=Net::FTP->new($server) or $success="false";
$ftp->login($user, $password) or $success="false";
$ftp->pasv() or $success="false";
$ftp->binary() or $success="false";
$ftp->cwd($dir) or $success='false';
print $ftp->cwd($dir);
# I am unable to open the directory that exists in the server which I
have
# mentioned with $dir name.
opendir(SRC, $dir);
my @dir_files = readdir(SRC);
foreach my $file (@dir_files)
{
if($file eq $dir_name)
{
$ret = 0;
closedir(SRC);
last;
}
}
if($ret ne 0)
{
$ftp->mkdir($folder_name) or $success='false';
}
$ftp->cwd($dir."/".$folder_name) or $success='false';
Can anybody help me how to read the contents of a directory in the
server.