FTP Uploading problem in perl scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cjayaram2001
    New Member
    • Nov 2008
    • 3

    FTP Uploading problem in perl scripts

    Hi All,

    I have problem while uploading files to remote FTP using perl scripts if the size is high, also FTP session is cut . Can any one suggest me how to overcome this issue?.

    Regards
    Jayaram
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Can you please provide more information? We need to see a log file or the output of what is happening so that we can help you. Also, can you please post your script (enclosed in code tags)?

    Thanks!

    Jeff

    Comment

    • cjayaram2001
      New Member
      • Nov 2008
      • 3

      #3
      Hi Jeff,

      Pl find below the sample script

      my $host = "172.16.1.2 58" ; ## testing server(FTP) details
      my $user = "Ninestars" ;
      my $pass = "0brette1ns " ;

      my $projectname = "KIS-New";
      my $uploadfile;

      my $Title = "";
      my @xmlfile = "";



      print "Starting FTP at process $$ ($host)\nUpload s .ZIP file to the KNIPSEL server\n";

      my $destdir = "/Upload" ; ## Dest directory where the files be uploaded to, creates dir if does not exists
      my $workdir = $ARGV[1];#existing
      my $delete_sourcef ile = -1 ; ## Do you want to delete the file after downloading it?
      my $download_file = 1 ; ## Well, do you want to download?
      our @ERRORS = () ;
      my $newerr = 0 ;
      my $fsize;
      my $filenotpresent = 0;

      my $FTPList = $ARGV[0];
      chomp($FTPList) ;

      $workdir =~ s/\\/\\\\/g;
      chomp($workdir) ;

      open(FTPLST,"$F TPList") || die "Unable to open the $FTPList file \n";

      my $batchname;
      #chomp($batchna me);

      #$destdir .= "$batchname \\";
      #$backupdir .= "$batchname \\";


      # MAKE A CONNECTION TO THE SERVER
      my $ftp = Net::FTP->new($host,Time out=>10) or $newerr=1;
      push @ERRORS, "Can't ftp to host: $!\n" if $newerr;
      myerr() if $newerr ;

      # Login to the server
      $ftp->login($user,$p ass) or $newerr = 1;
      push @ERRORS, $ftp->message if $newerr;
      myerr() if $newerr;

      print "Getting list of files \n";

      #Set the transfer mode binary
      $ftp -> binary ;
      $ftp -> cwd("$destdir") ;
      #$ftp -> cwd('$batchname ');
      #my $size = $ftp -> size ( $_ );

      while(<FTPLST>)
      {
      chomp($_);
      ($batchname, $uploadfile) = split(",",$_);
      $Title = (split("_",$upl oadfile))[0];
      $ftp -> cwd("$destdir") ;
      # $ftp -> cwd($Publicatio n{lc($Title)}); #CHANGE TO PUBLISHER DIR

      if ( -f "$workdir\\$bat chname\\$upload file.zip.tmp" ) {
      print " Uploading ($uploadfile) \n";
      $ftp -> put("$workdir\\ $batchname\\$up loadfile.zip", $uploadfile.".z ip") or $newerr=1;
      push @ERRORS, $ftp->message if $newerr;
      if ($newerr)
      {
      myerr();
      $filenotpresent =1;
      print "Error transferring the file $uploadfile";
      <STDIN>;
      }
      else
      {
      print "Upload finished for $batchname\\$up loadfile @ $host \n";
      if (! -d "$workdir\\$bat chname")
      {
      mkdir("$workdir \\$batchname");
      }
      elsif ( ! -d "$workdir\\$bat chname\\done")
      {
      mkdir("$workdir \\$batchname\\d one");
      }
      rename("$workdi r\\$batchname\\ $uploadfile.zip ", "$workdir\\$bat chname\\done\\$ uploadfile.zip" ) || print "unable to move the file to $workdir\\$batc hname\\done directory \n";
      print "File moved to $workdir\\$batc hname\\done directory \n";
      }
      }
      else
      {
      print "ZIP $workdir . $batchname . $uploadfile NOT transferred to KNIPSEL server. File not present\n";
      $filenotpresent =1;
      <STDIN>;
      }

      }


      if ($filenotpresen t == 1)
      {
      $newerr = $filenotpresent ;
      }

      opendir(XMLLIST , "$workdir\\$bat chname") || die "unable to open the directory\n";
      my @xmlfile = grep /\.xml$/i,readdir(XMLLI ST);
      if ($#xmlfile >= 0)
      {
      foreach my $xmlfile (@xmlfile)
      {
      #print $xmlfile;<STDIN >;
      $ftp -> put("$workdir\\ $batchname\\$xm lfile",$xmlfile ) or $newerr = 1;
      rename("$workdi r\\$batchname\\ $xmlfile", "$workdir\\$bat chname\\done\\$ xmlfile") || print "unable to move the XML to $workdir\\$batc hname\\done directory \n";
      }

      push @ERRORS, $ftp->message if $newerr;
      if ($newerr)
      {
      myerr();
      $filenotpresent =1;
      print "Error transferring the file $uploadfile";
      <STDIN>;
      }

      #print "XML PRESENT\n";<STD IN>;
      }
      $ftp->quit();

      exit($newerr);

      sub myerr
      {
      print "Error: \n";
      print @ERRORS;
      $newerr = 0;
      exit 0;
      }


      I am facing problem while some zip file size is large and ftp session gets cut while uploading files to remote customer FTP.

      Regards,
      Jayaram

      Comment

      Working...