I am using Net::FTP to transfer MP3 files from Linux to a Windows environment. It works almost perfect. However, I have two functions below, one for sending a file from Linux->Windows, and one for deleting the uploaded file. I am using a CGI::App framework and outputting with HTML::Template.
If I upload a file, check if it exists, delete the file, check if it's gone, when I upload the file again I got a timeout error from the Net::FTP->new().
I need to find out what's wrong, so I put the call to Net::FTP in Debug mode. Does anyone know what's causing the problem? or does anyone know how to print out the debugging information to an HTML::Template file?
sub sendFile {
# application object
my $self = shift;
# load template files
my $tmpl = $self->param('info' => $self->load_tmpl
('info.phtml'));
# create an ftp object
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21) or di
+e "Cannot connect to host: $@";
# login to the ftp server
$ftp->login("user",'pass') or die $ftp->message;
# get root directory
$ftp->cwd() or die $ftp->message;
# get the filename
my $filename = "dir+filename";
# check if file exist
if(-e $filename){
# send file in binary mode
$ftp->binary;
# send a file to the remote server
$ftp->put($filename) or die $ftp->message;
}
# quit the ftp connection
$ftp->quit;
# output
return $tmpl->output;
}
sub deleteFile {
# application object
my $self = shift;
# load template files
my $tmpl = $self->param('info' => $self->load_tmpl
('info.phtml'));
# create an ftp object
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21) or di
+e "Cannot connect to host: $@";
# login to the ftp server
$ftp->login("user",'pass') or die $ftp->message;
# get root directory
$ftp->cwd() or die $ftp->message;
# get the filename
my $filename = "filename";
# delete a file to the remote server
$ftp->delete($filename);
# quit the ftp connection
$ftp->quit;
# output
return $tmpl->output;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.