FAQ
Hi All,

Me again!

I'm having a bit of a struggle trying to write the contents of one file in
another, via FTP.

Here's the deal: Someone (I know who, but...) is constantly "diddling" with
the page count for a departmental web page I've done. He likes to change the
counts to something fairly astronomical like, "932305709023" hits or
somesuch... The count itself is stored in a simple text file called
"default.asp.cnt" on the server. It's easy for him, with admin rights
<sigh!> to diddle the file.

So, I figured if I FTP'd the file, looked at it, if the change was out of
bounds (say more than 100 hits since the last check) within a certain time
(say 5 minutes), I'll say it was tampered with. I would re-write it with the
previous value, and repeat processing.

This is my first time using the FTP library & it's objects.

The Crux of The Matter:

I want countff ("count from file") to be the # of hits, as stored in
"default.asp.cnt".

I have the following lines of code (among others! But I feel the offending
code may be here...):

countff = str((ftp.retrlines('retr default.asp.cnt')))
ftp.retrlines('retr default.asp.cnt')
print "countff var is: ", countff

When this runs, countff - which I WANT to contain a # from my page hit count
file - is actually "226 Transfer complete."!! So I'm snagging the result
rather than the file contents itself. What am I doing incorrectly, and how
do I fix it?

I realize that both lines:
countff = str((ftp.retrlines('retr default.asp.cnt')))
ftp.retrlines('retr default.asp.cnt')
Do essentially the same thing. However, I can't write THAT value to a file.
Both lines display a the total # of hits to the page, as stored in the
"default.asp.cnt" on the server.

All help TRULY appreciated,

--Pete

python AT wcom DOT com

Search Discussions

  • Terry Reedy at May 15, 2002 at 9:19 pm
    "Peter F. Ferris" <python at gbronline.com> wrote in message
    news:mailman.1021491928.31511.python-list at python.org...
    ...
    Here's the deal: Someone (I know who, but...) is constantly
    "diddling" with
    the page count for a departmental web page I've done. He likes to
    change the
    counts to something fairly astronomical like, "932305709023" hits or
    somesuch... The count itself is stored in a simple text file called
    "default.asp.cnt" on the server. It's easy for him, with admin rights
    <sigh!> to diddle the file. ...
    The Crux of The Matter:
    is that gilded garbage is still garbage,

    and that gargage in means garbage out (gigo),

    and that any pretense at fixing willfully corrupted data is just that.

    So don't play that game.

    Either try to stop the vandalism (some technical possibilities:
    encrypt the data; send page hit packets to a more secure system) or
    find something better to do.
    All help TRULY appreciated,
    If so, more is available.

    Terry J. Reedy
  • Skip Montanaro at May 15, 2002 at 11:48 pm

    Here's the deal: Someone (I know who, but...) is constantly
    "diddling" with the page count for a departmental web page I've
    done. He likes to change the counts to something fairly astronomical
    like, "932305709023" hits or somesuch...
    Terry> So don't play that game.

    Terry> Either try to stop the vandalism (some technical possibilities:
    Terry> encrypt the data; send page hit packets to a more secure system)
    Terry> or find something better to do.

    'ave 'im flogged, I say...

    --
    Skip Montanaro (skip at pobox.com - http://www.mojam.com/)
    "Excellant Written and Communications Skills required" - seen on chi.jobs
  • Peter F. Ferris at May 16, 2002 at 12:09 am
    True. I could just report him to the manager, etc; etc. But I guess I'm
    supposed to appreciate the intellectual challenge presented here. %^} I've
    politely asked him to cease, he has not. He thinks he's being "funny" --
    heeheehaahaa! Not to mention he's someone I'll "need" from time to time.
    And I'm a PYTHON NEWBIE, I figured it would be a good exercise! ;-)

    My real problem, clearly stated as I can:

    I'm seeing the correct count from the file display on my screen, but I can
    not 'catch'/assign it to a variable to write it to a file.

    Thanks for the suggestions though.

    --Pete

    Re flogging: In Oklahoma, we use cattle prods! %^}

    : -----Original Message-----
    : From: python-list-admin at python.org
    : [mailto:python-list-admin at python.org]On Behalf Of Skip Montanaro
    : Sent: Wednesday, May 15, 2002 18:49
    : To: Terry Reedy
    : Cc: python-list at python.org
    : Subject: Re: Page Hit Counter Vandalism & Writing FTP Results
    :
    :
    :
    : >> Here's the deal: Someone (I know who, but...) is constantly
    : >> "diddling" with the page count for a departmental web page I've
    : >> done. He likes to change the counts to something fairly
    : astronomical
    : >> like, "932305709023" hits or somesuch...
    :
    : Terry> So don't play that game.
    :
    : Terry> Either try to stop the vandalism (some technical possibilities:
    : Terry> encrypt the data; send page hit packets to a more
    : secure system)
    : Terry> or find something better to do.
    :
    : 'ave 'im flogged, I say...
    :
    : --
    : Skip Montanaro (skip at pobox.com - http://www.mojam.com/)
    : "Excellant Written and Communications Skills required" - seen on chi.jobs
    :
    :
    :
  • Neil Schemenauer at May 16, 2002 at 8:16 pm

    Skip Montanaro wrote:
    Terry> Either try to stop the vandalism (some technical possibilities:
    Terry> encrypt the data; send page hit packets to a more secure system)
    Terry> or find something better to do.

    'ave 'im flogged, I say...
    Nail 'im up I say. Nail some sense into 'em...
  • Greg Ewing at May 16, 2002 at 12:40 am

    "Peter F. Ferris" wrote:
    Here's the deal: Someone (I know who, but...) is constantly "diddling" with
    the page count for a departmental web page I've done.
    ... It's easy for him, with admin rights <sigh!> to diddle the file.
    What is such an obviously immature person doing with
    admin rights to the server? Perhaps you would be better
    off seeking someone with higher authority to solve
    *that* problem instead.

    --
    Greg Ewing, Computer Science Dept, University of Canterbury,
    Christchurch, New Zealand
    To get my email address, please visit my web page:
    http://www.cosc.canterbury.ac.nz/~greg
  • Martin Franklin at May 16, 2002 at 9:54 am

    On Wednesday 15 May 2002 7:44 pm, Peter F. Ferris wrote:
    countff = str((ftp.retrlines('retr default.asp.cnt')))
    ftp.retrlines('retr default.asp.cnt')
    print "countff var is: ", countff


    Peter,

    pydoc ftplib
    ...... <snip>
    retrlines(self, cmd, callback=None)
    Retrieve data in line mode.
    The argument is a RETR or LIST command.
    The callback function (2nd argument) is called for each line,
    with trailing CRLF stripped. This creates a new port for you.
    print_line() is the default callback.
    print_line being a function in ftplib that errrr prints the line to stdout!
    so..... you need to use that second argument... somthing like


    data=[] # empty list to store your data in!


    # append method called for every 'line' in the remote file
    ftp.retrlines('retr default.asp.cnt', data.append)

    Cheers
    Martin
  • Peter F. Ferris at May 16, 2002 at 11:53 am
    The social-political implications aside for just a moment (whether or not I
    should report the guy, whether I should use 'software' to fix a 'people'
    problem, etc; etc; is beyond what I intended to discuss, granted I may've
    opened the can of worms!).

    The actual line of code I needed is:

    ftp.retrlines('retr default.asp.cnt',storagef.write)

    the problem was that last part -- ",storagef.write"! I was missing that
    portion. Thus, I was displaying, but never writing, the contents of the
    retrieved file.

    I actually found the instructive code example at:

    http://www.python.org/doc/lj21.html -- about 1/3 - 1/2 way down the page.

    Thanks for all of the help & hints anyhow.

    Cordially,

    --Peter
  • Stefan Schwarzer at May 18, 2002 at 6:20 pm
    Hello Peter

    "Peter F. Ferris" wrote:
    I'm having a bit of a struggle trying to write the contents of one file in
    another, via FTP.
    [...]

    You may also look at ftputil at
    http://www.ndh.net/home/sschwarzer/python/python_software.html

    The module requires Python 2.1+ .

    Stefan

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 15, '02 at 7:44p
activeMay 18, '02 at 6:20p
posts9
users9
websitepython.org

People

Translate

site design / logo © 2022 Grokbase