开发者

perl ftp not working

Script works fine, but ftp code uploading the xls but uploading with 0 byte, but if ftp code present in before of the following snippet, FTP Works Fine,

What is the error in code,

my $workbook = Spreadsheet::WriteExcel->new('TestRPT.xls'); my $worksheet = $workbook->add_worksheet('TestRPT Report');

#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Spreadsheet::WriteExcel;
use POSIX qw(strftime);


my $CurTimeStamp=time;
my $LastSunTimestamp=($CurTimeStamp - 168*60*60);
my $row;
my $PinNumber;
my $PinAmount;
my $get_date;
my $get_time;
my $get_time_stamp;
my $DoFTPFlg = "yes";


# Create a new workbook and add a worksheet.
my $workbook  = Spreadsheet::WriteExcel->new('TestRPT.xls');
my $worksheet = $workbook->add_worksheet('TestRPT Report');


# Write some text. in write function First Argument for ROW, Second Argument for COLUMN, Third Argument for Title/Text to display
$worksheet->write(0, 0,  'val1');
$worksheet->write(0, 1,  'val2');
$worksheet->write(0, 2,  'val3');
$worksheet->write(0, 3,  'val4');
my $cnt = 1;
    $get_time_stamp = time;
    $get_date = strftime("%m/%d/%y",localtime($get_time_stamp));
    $get_time = strftime("%H:%M",localtime($get_time_stamp));
    # Write some numbers.
    $worksheet->write($cnt, 0,  "val1");          
    $worksheet->write($cnt, 1,  "val2");    
    $worksheet-开发者_Python百科>write($cnt, 2,  "val3"); 
    $worksheet->write($cnt, 3,  "val4"); 




if ($DoFTPFlg eq "yes") {
    print "DO FTP";
    use Net::FTP;
    my $ftp;
    $ftp = Net::FTP->new("mysite.in", Debug => 0);
    $ftp->login("user",'pass');
    $ftp->cwd("/www/");
    $ftp->put("TestRPT.xls");
    $ftp->quit; 

}


You should close your $workbook object before trying to do anything with the file.

From the documentation:

An explicit close() is required if the file must be closed prior to performing some external action on it such as copying it, reading its size or attaching it to an email.


Try a slight modification on your code. Instead of

$ftp->put("TestRPT.xls");

Create another file in the www directory and try to ftp that file. If that file is called test.txt, change your line to:

$ftp->put("TestRPT.xls");

Thus, the only change in your code is the name of the file being FTP'd. If your FTP works, the problem isn't with the FTP, but with the Spreadsheet::WriteExcel module. As Mat has already stated, you need to do an explicit close on your object.

If your FTP doesn't work, it probably is an issue with the FTP call (although it looks fine to me).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜