Google Grupper understøtter ikke længere nye Usenet-opslag eller -abonnementer. Tidligere indhold er fortsat synligt.

Check if a file exists on a ftp server?

7.042 visninger
Gå til det første ulæste opslag

Tessa Lau

ulæst,
11. jul. 1996, 03.00.0011.07.1996
til

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

ulæst,
11. jul. 1996, 03.00.0011.07.1996
til

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

ulæst,
12. jul. 1996, 03.00.0012.07.1996
til

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

ulæst,
12. jul. 1996, 03.00.0012.07.1996
til

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 nye opslag