Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi!
I'm trying to ftp some files from a remote server using the net::ftp module. It was working fine all these days, when I did a get|put etc.
Recently, while I was performing an ftp of a zip file of size above 4000 kb, I get an error while opening it, which says "....69 bytes missing....". I have no idea why.
Here's my script:
#!/usr/bin/perl -w use strict; use Net::FTP; use Cwd; $|++; my ($ftpmessage, $ftp, $sourcefile, $option, $remote_path); my ($pwdr, $logfile); my %parm = ( ftphost => '255.255.255.255', ftpuser => 'user', ftppass => 'passwd', ); sub get_the_file($) { my $source=shift; $ftp->get("$source") or LogIt('exit', "Error uploading.\nDisk space or permissions probl +ems?\n"); $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); } sub get_the_pwd { my $fullpath=$ftp->pwd(); print "Fullpathname $fullpath\n"; $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); } sub set_the_pwd($) { my $directory=shift; $ftp->cwd("$directory") or LogIt('exit', "Could not change the directory to $directory! \ +n"); $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); } # Print message with date+timestamp to logfile. # Abort program if instructed to. sub LogIt { my $exit = $_[0]; my $msg = $_[1]; print LOG "$msg"; #my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me(time); print LOG scalar localtime(), "\n"; #$year+1900,"-",$mon+1,"$mday $hour:$min:$sec\n"; exit if ($exit eq 'exit' ); } { $pwdr=cwd;; chomp($pwdr); if ( $#ARGV == -1 ) { print "$0:Usage $0 get\|put\|list path filename\n"; exit; } elsif ($ARGV[0] !~ /(get)|(put)|(list)/i) { print "$0:Usage $0 get\|put\|list path filename\n"; exit; } $option=$ARGV[0]; $remote_path=$ARGV[1]; $sourcefile=$ARGV[2]; if ( -e "$pwdr\\FTPLogs") { print "Writing Log file in $pwdr\\FTPL +ogs...\n"; } else { mkdir("$pwdr\\FTPLogs",0777) || die "Sorry, I couldn't crea +te $pwdr\\FTPLogs folder $!\n"; } ($main::sec,$main::min,$main::hour,$main::mday,$main::mon,$main::y +ear,,,) = localtime(time); $main::mon+=1; $main::year+=1900; $logfile="$pwdr\\FTPLogs\\FTP_log_$main::mday\_$main::mon\_$main:: +year\_$main::hour\_$main::min\_$main::sec"; open (LOG, ">>$logfile") or die "Error opening $logfile: Reason$! +"; LogIt('noexit', "\n\n********************************************* +***************\n Started run\n"); print LOG " Destination server $parm{ftphost} Destination user $parm{ftpuser} Log file $logfile Upload script $0 Perl $] Net::FTP $Net::FTP::VERSION Local OS $^O\n", ; if ((defined $sourcefile) && ($option =~ /put/i)) { unless (-r $sourcefile && -T $sourcefile) { LogIt('exit', "Error with source file $sourcefile.\nIs not readable or +ASCII.\n" ); } } $ftp = Net::FTP->new($parm{ftphost}) or LogIt('exit', "Error connecting.\nNetwork or server problem?\n") +; $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); $ftp->login($parm{ftpuser}, $parm{ftppass}) or LogIt('exit', "Error logging in.\nHas ID or password changed?\n" +); $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); $ftp->ascii(); $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); set_the_pwd("$remote_path"); get_the_pwd(); if ($option =~ /put/i) { put_the_file("$sourcefile"); } elsif ($option =~ /get/i) { get_the_file("$sourcefile"); } else { get_file_list(); } $ftp->quit() or LogIt('exit', "Error disconnecting.\n???\­n"); $ftpmessage=$ftp->message(); LogIt('FTP Says:', "$ftpmessage\n"); close LOG or die "Error closing $sourcefile: Reason$!"; }
Please let me know in case I have to make any changes or anything.
Thanks!
SRK.

Edit, BazB. Add readmore, change title (was "Net::FTP").


In reply to File corrupt when using Net::FTP by rupesh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found