From 1e7fd48afd844c82d7d3d9a07a616bee18e4f67a Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 7 Sep 2006 12:21:41 +0000 Subject: [PATCH] added size method to ftpc git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2508 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/net/ftpc.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/de/anomic/net/ftpc.java b/source/de/anomic/net/ftpc.java index 0a86f796f..44d537190 100644 --- a/source/de/anomic/net/ftpc.java +++ b/source/de/anomic/net/ftpc.java @@ -1311,6 +1311,34 @@ cd .. return GET(); } + public int size(String path) throws IOException { + // get the size of a file. If the given path targets to a directory, a -1 is returned + // this function is not supported by standard rfc 959. The method is descibed in + // http://www.ietf.org/internet-drafts/draft-ietf-ftpext-mlst-16.txt + // if the method is not supported by the target server, this throws an IOException with the + // server response as exception message + + // send command to the control port + send("SIZE " + path); + + // read status of the command from the control port + String reply = receive(); + + // get status code + int status = Integer.parseInt(reply.substring(0, 3)); + + // starting data transaction + if (status == 213) { + try { + return Integer.parseInt(reply.substring(4)); + } catch (NumberFormatException e) { + throw new IOException(reply); + } + } else { + throw new IOException(reply); + } + } + public boolean USER() { if (cmd.length != 3) { err.println(logPrefix + "---- Syntax: USER ");