Skip navigation

Category Archives: Perl

Needed to run some reports out of Oracle then FTP them. Could probably do this easier with normal shell command or something but I only have access to Perl at work. So thankfully NET::FTP is an installed module which made this quite painless.

The main thing to take away from this is the parameters you can use for NET::FTP, mainly using passive mode which I found a big help when the FTP server blocked active mode requests. Also to make this useful in any way, writing debug/ error tracking logic is very very useful since we are dealing with external servers and numerous issues can arise.

FTP files with Perl and NET::FTP

3 lines of code to output the date in Perl. In this instance getting yesterdays date.

Firstly we get our time by calling the time function, which stores the number of seconds since the systems epoch time – normally 1st January 1970 UTC – If I want yestedays date I call the time function minus the number of seconds in the day, 24 * 60 * 60, multiply that by days in week, month, year etc.. to get other dates.

Getting a date in Perl using time and localtime

Sending a mail attachment using NET::SMTP is pretty easy, the only really hard bit is making sure the module is installed on your server and that of course you can run Perl. I’ve written this primarily from doing this from a server but you could ust as easily use this on websites etc…

Basically to send an attachment we need to read the file into a string/ array in Perl which in turn MIME will then associate the content of this string to a reserved file to be attached. We also use MIME to send mutipart emails, so we’ll be using boundaries to separate each part, the headers, the message and the attachment. The code is below:

http://luckylarry.co.uk/2009/07/sending-mail-and-attachments-from-perl-using-netsmtp/

Follow

Get every new post delivered to your Inbox.