Solved

PERL Time problem

Posted on 2004-10-25
181 Views
Last Modified: 2010-03-05
Hi All,

I have a website where the time is displayed, and it works just fine.  We have a server in our office, where we do our updates via a web interface.  When we are happy with what every thing looks like, we click a button on the interface, it runs a perl script, and ftp's files over to the server at our isp/web host, to our main website.  This all works fine.  The server in our office is getting very old, so I moved all of the files from it to a newer server, corrected the addressing inthe perl scripts, installed everything (i Think!) that is necessary, etc.  When I try to do the same process on the newer server, it ftp's all of the files it should, however that date on our website will revert back to January 1, 1970.  I'm familiar with how PERL figures out date and time, counting non leap seconds from 1970 etc.  My question is why is this all of the sudden changing the dates?  All we are doing is ftping (using Net::ftp) text files.  Has anyone ever encountered this problem?

Thanks

Brian
0
Question by:wxman1
    9 Comments
     
    LVL 16

    Expert Comment

    by:manav_mathur
    Brian,
    One thing that you have not mentioned is how are you displaying time on your website.
    Are you using CGI scripting or some other method......

    Manav
    0
     

    Author Comment

    by:wxman1
    Manav,

    It is perl scripting using CGI.

    Brian
    0
     
    LVL 16

    Accepted Solution

    by:
    okay!!

    And you are using localtime to get the updated time.
    Two of the stupidest suggestions that I can come with are

    1) Have you by mistake tweaked with the actual code while moving servers.
    2) Does the server have the time set??

    Can you tell me what version of PERL you are using??

    Manav
    0
     

    Author Comment

    by:wxman1
    Manav,

    1)  No I haven't touched the code, except for changing the addressing as the directory structure on the new server is slightly different.

    2)  The older server is set for the current time.  The new server is set at GMT time, as most of our work is done in GMT.  The webserver, where are actual website resides, I am not sure.

    There is a difference between the versions of PERL, the older server is running 5.22, and the newer one is running 5.8 (Active States version).  I'm not sure about the webserver hosted at our isp.

    Brian
    0
     
    LVL 16

    Expert Comment

    by:manav_mathur
    If possible, can I see the PERL script which you run to ftp the files.

    One thing that seems is that there's a version conflict somewhere. Your webserver has no role to play in this error, because Im assuming that the PERL script used to FTP files also inserts the last updated date somewhere in the webpage. SO I guess having a look at it might solve the problem

    one more thing, you can go thru the docs for localtime. Even I have Active state 5.6.

    Manav
    0
     

    Author Comment

    by:wxman1
    Script is below:
    ###################
    use CGI;
    use Net::FTP;

    require "c:/Inetpub/wwwroot/oldweb/www.weather.bm/cgi-bin/weather-util.pl";

    $LOCATION="REMOTE";

    chdir("$HOMEDIR/cgi-bin");

    $in=new CGI;

    # Make sure that data was posted (ie. CGI was started properly for an update).
    if ($in->param("u") eq "1") {

       # The following actions always take place, whether CGI run on main server or remotely (at BWS)...
       print "Location: /update/complete.html\n\n";

       if (opendir(DIR,".")) {
          @files=readdir(DIR);
          closedir(DIR);

          # Mark "old" files for deletion - try to be a bit cleaner. :^)
          foreach $file(@files) {
             if ($file=~/^cur-[^\.]+\.txt$/) { $Delete{$file}=1; }
             print $file."\n";
          }

          # Copy new files to new names.
          foreach $file(@files) {
             if ($file=~/^tmp-([^\.]+)\.txt$/) {
                $name=$1;
                system("copy $file cur-$name.txt");
                $Delete{"cur-$name.txt"}=0;
                print "Copied $file to cur-$name.txt\n";

                # Make a record of files to keep (and where to put on main server), if FTPing them later is needed.
                $Keep{"cur-$name.txt"}="";
             }
          }

          # Delete unneeded files.
          foreach $file(keys %Delete) {
             if ($Delete{$file}) {
                unlink($file);
                print "Deleted $file.\n";
             }
          }
    }

    if ($LOCATION eq "REMOTE") {

          # Remote machine must also FTP all the updated, current TXT files it has to the server.
          # (all files that have a cur-xxx.txt and tmp-xxx.txt versions)
          SendFTP("i.p.address","username","password",%Keep);
       }

    else {
       print "Content-type: text/html\n\n";
       print <<ENDTEXT;
    <HTML>
    <HEAD>
    <TITLE>Weather Page Update</TITLE>
    </HEAD>
    <BODY bgcolor=#e3fff2 text=#000000 link=#0a50a1 vlink=#0a50a1 background="/back/coral-thin.gif">
    <FONT face="Arial, Geneva, Helvetica, San-serif">
    <TABLE border=0>
    <TR><TD valign=top width=220><IMG src="/blank.gif" width=220 height=1></TD>
        <TD>
        <B>Update Weather Page.</B><P>

        The weather pages have <B>not</B> been updated with the files from the preview site - please do not bookmark this page.
       
        <P><A href="/">Go to main weather page</A><BR>
        <A href="/update/">Go to preview area</A></P>
        </TD>
    </TR>
    </TABLE>
    </FONT>
    </BODY>
    </HTML>
    ENDTEXT
    }
    exit(0);

    sub SendFTP {
    # Performs FTP Upload functions.

       my($host,$user,$pass,%files)=@_;
       my($dir,$file,$ext,$mode,$ftp);

       my(%ASCII)=("TXT"=>1,"HTML"=>1,"SHTML"=>1,"HTM"=>1,"PL"=>1,"PM"=>1);

       $mode="UNKNOWN";
       if ($ftp = Net::FTP->new($host)) {
          if ($ftp->login($user,$pass)) {
             
             foreach $file(sort keys %files) {

                # Change to appropriate directory.
                $dir=$files{$file};
                if ($dir ne "") { $ftp->cwd($dir); }

                # Change mode if necessary.
                if ($file=~/\.(.+)$/) { $ext=uc($1); } else { $ext="none"; }
                if (($ASCII{$ext})&&($mode ne "ASCII")) { $ftp->ascii(); $mode="ASCII"; }
                elsif ((!($ASCII{$ext}))&&($mode ne "BINARY")) { $ftp->binary(); $mode="BINARY"; }

                # Send file.
                $ftp->put($file);
             }
          }
          $ftp->quit;
          return 1;
       }
       return 0;
    }
    0
     

    Author Comment

    by:wxman1
    sorry, forgot a line of code

    After :
    if ($LOCATION eq "REMOTE") {

          # Remote machine must also FTP all the updated, current TXT files it has to the server.
          # (all files that have a cur-xxx.txt and tmp-xxx.txt versions)
          SendFTP("i.p.address","username","password",%Keep);
       }


    should be:

     # Machines should also FTP graphics and HTML for tracking maps if needed.
       %Keep=();
       foreach $file(@files) {
          if (($file=~/^map-\d+-\d+.png$/)||($file=~/^map-\d+-bg.png$/)||($file=~/^map-\d+-plot.html$/)) { $Keep{$file}=""; }
       }
    0
     

    Author Comment

    by:wxman1
    Manav,

    Well I figured out what my problem was, the Net::ftp was not using passive mode!  I don't know why that was causing the problems, but I have corrected it and it now works.  Since you were kind enough to try and help, the points are yours.

    Cheers,

    Brian
    0
     
    LVL 16

    Expert Comment

    by:manav_mathur
    Great!!

    Sorry couldnt help you more last time. It was 10 in the night and I had to leave my office.

    Manav
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now