Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w # ftpgp.pl # pod at tail use strict; use Net::FTP; my %file = ( source => 'ftpgp.in', dest => 'ftpgp.out', log => 'ftpgp.log', ); my %parm = ( ftphost => '', ftpuser => '', ftppass => '', ); open (LOG, ">>$file{log}") or die "Error opening $file{log}: $!"; LogIt('noexit', "\n Started run "); print LOG " Sourcefile $file{source} Destination file $file{dest} Destination server $parm{ftphost} Destination user $parm{ftpuser} Log file $file{log} Upload script $0 Perl $] Net::FTP $Net::FTP::VERSION Local OS $^O\n", ; unless (-r $file{source} && -T _) { LogIt('exit', "Error with source file $file{source}.\nIs not readable or ASCII +.\n" ); } my $ftp = Net::FTP->new($parm{ftphost}) or LogIt('exit', "Error connecting.\nNetwork or server problem?\n"); $ftp->login($parm{ftpuser}, $parm{ftppass}) or LogIt('exit', "Error logging in.\nHas ID or password changed?\n"); $ftp->ascii(); $ftp->put($file{source}, $file{dest}) or LogIt('exit', "Error uploading.\nDisk space or permissions problems +?\n"); $ftp->quit() or LogIt('exit', "Error disconnecting.\n???\n"); LogIt('noexit', " Finished FTP put "); close LOG or die "Error closing $file{log}: $!"; ###################################################################### +##### # 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) = localtime +(time); print LOG $year+1900,"-",$mon+1,"-$mday $hour:$min:$sec\n"; ; exit if ($exit eq 'exit' ); } ###################################################################### +##### =head1 Title ftpgp.pl =head1 Description Non-interactive script to upload a file to specified FTP server. Intended to be run repeatedly from (cron|at|scheduler). Logs success or failure with timestamp and Perl+module versions. Would be trivial to tweak for multiple files. Source, dest, and log files should usually be specified by full files +pec. =head1 Updated 2001-06-21 19:35 CDT Simplify with localtime but not loading Time::localtime module. 2001-06-20 17:40 CDT Add error runs to example logfile. Add read+text filetests for source file. Combine ErrAndExit, LogMessage, and MyTime into LogIt() with passed + param. 2001-06-19 22:15 CDT Post to PerlMonks. Initial working code. =head1 Todos Variableize $ftp->(ascii|binary). Variableize $ftp->(get|put). Debug error only seen with ActivePerl: "uninitialized value in concatenation (.) at D:/Perl/site/lib/Net/Config.pm line 44." Employ Net::FTP's own error handling. =head1 Tested ActivePerl 5.61, Win2kPro Perl 5.006001, Cygwin 1.3.2, Win2kPro Perl 5.00503, Debian 2.2r3 Net::FTP 2.56 Time::localtime 1.01 Error handling for: unreadable or nonexistant sourcefile binary (non-ASCII) sourcefile unreachable host bad ID wrong password no write perms at target =head1 Example runlog Started run 21:55:1 6-19-2001 Sourcefile C:\Data\ftpgp.in Destination file /incoming/ftpgp.out Destination server ozark.bbq Destination user clem Log file C:\data\ftpgp.log Upload script C:\Documents and Settings\clem\Perl\ftpgp.pl Perl 5.006 Net::FTP 2.56 Local OS MSWin32 Finished FTP put 21:55:1 6-19-2001 Error with source file ftpgp.in. Is not readable or ASCII. 2001-6-21 19:37:43 Error connecting. Network or server problem? 2001-6-20 15:53:29 Error logging in. Has ID or password changed? 2001-6-20 15:53:49 Error uploading. Disk space or permissions problems? 2001-6-20 16:3:53 =head1 Author ybiC =head1 Credits Thanks to Kevman, grinder, jeffa, and damian1301 for feedback. Oh yeah, and to some guy named vroom. =cut

In reply to (code) Just Another Net::FTP Script by ybiC

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



  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2019-10-22 02:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?