Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check if a file exists on a ftp server?

7,080 views
Skip to first unread message

Tessa Lau

unread,
Jul 11, 1996, 3:00:00 AM7/11/96
to

Hi there,

I'm writing a script which verifies the existence of several files on
different ftp servers. What's the best way to verify existence, without
actually getting the file? Right now, my solution is to do an
ftp.sendcmd('stat /path/to/file') and parse the results---but this only
works when the remote server is a unix server and returns the output of
/bin/ls. And it gets messy when I want to stat a directory instead of a
file.

Is there a better way to do this?

Thanks!
--Tessa

--
Tessa Lau <tl...@cs.washington.edu>
Maintainer of the Linux Game Tome (using python!)
<http://www.cs.washington.edu/homes/tlau/linux-game.html>

Benny Shomer

unread,
Jul 11, 1996, 3:00:00 AM7/11/96
to

Tessa Lau (tl...@cs.washington.edu) wrote:
: Hi there,

: I'm writing a script which verifies the existence of several files on
: different ftp servers. What's the best way to verify existence, without
: actually getting the file? Right now, my solution is to do an
: ftp.sendcmd('stat /path/to/file') and parse the results---but this only
: works when the remote server is a unix server and returns the output of
: /bin/ls. And it gets messy when I want to stat a directory instead of a
: file.

Issue:

file_list = ftp.nlst()

Analyse the contents of file_list.

I hope it helps,

Benny.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Benny Shomer, Ph.D. Biological User Support
EMBL outstation - The EBI, Tel: +44-223-494437
Hinxton Hall, Hinxton, Fax: +44-223-494468
Cambridge CB10 1RQ, UK Email: bsh...@EBI.ac.uk

~~~~~~~http://www.ebi.ac.uk/ebi_docs/staff/benny.html~~~~~~~

Martin v. Loewis

unread,
Jul 12, 1996, 3:00:00 AM7/12/96
to

In article <DuD4...@beaver.cs.washington.edu>,

Tessa Lau <tl...@cs.washington.edu> wrote:
>I'm writing a script which verifies the existence of several files on
>different ftp servers. What's the best way to verify existence, without
>actually getting the file?

You could use the size command:

server.size(filename)

It throws an exception if the file is not there or if it is a directory.

Regards,
Martin

Tessa Lau

unread,
Jul 12, 1996, 3:00:00 AM7/12/96
to

Following up on my own post...

I just thought I'd note that not all ftp servers understand the size
command (ftp.microsoft.com, for example :). It throws an exception even if
the file exists.

It seems that nlst() is a more portable way to go. Thanks for the replies,
folks.

--Tessa

Martin v. Loewis (loe...@informatik.hu-berlin.de) wrote:
: In article <DuD4...@beaver.cs.washington.edu>,

: server.size(filename)

: Regards,
: Martin

--


Tessa Lau <tl...@cs.washington.edu>
Maintainer of the Linux Game Tome

<http://www.cs.washington.edu/homes/tlau/linux-game.html>

0 new messages