I am really, really new to Perl. I have been writing a script the processes a batch of web orders (sequential files) and reformats them to be transfered (FTP) to another system. My problem is, I can't seem to write decent code to do the job. I researched and found that NET::FTP is a good way to get it done but it is not installed on the server my script is running on nor can I ever get it installed. So, I have this snippet of code that supposedly would work with NET::FTP. It is supposed to read through a directory and transfer all of the files located there ( the only files will be the ones that I previously processed ) to a specific server; then deleting the processed files. Are there any Perl geniuses out there that can re-write my psuedo Perl using NET::FTP into code that just uses standard Perl components? Also, If anybody could catch any errors in my code snippet I would be very appreciative ( I obviously can't test it ).
Now, the majority of my script works and the reformatted files are placed into a directory ( lets call it /output ). This code snippet is the last, untested, part that uses NET:FTP to transfer the files out of that directory.
# read through the directory containing all of the formatted
# .ord files processed above and ftp them to SAP. delete the
# files when after they have been transfered.
use NET::FTP;
my $hostname='secret.server.mycompany.com;
my $user='anonymous';
my $password='anonymous';
my $ftp=Net::FTP -> new($hostname);
ftp->login($username,$password);
$ftp->ascii;
chdir( "output/$dir" );
opendir( DIR, "output/$dir" );
@files = readdir( DIR );
# transfer all of the output files
# in the output directory to SAP.
foreach( @files ) {
$filehandle = $_;
$ftp->put("output/$filehandle");
unlink( "$filehandle" );
} # end foreach
$ftp->quit;
Please remember that I am only a student and am still trying to learn. I know there are probably a gazillion better ways to do everything I have written and I would be glad to learn them all. Thanks for the help :)
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.