commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas Maujean" <nmauj...@hotmail.com>
Subject [FtpClient] : get the size of a file
Date Thu, 11 Aug 2005 17:19:16 GMT
Hi,

Here is the code to get the size of a file using FtpClient using the SIZE 
command of Ftp,

They have some adaptation to integrate it in FtpClient, but here you have 
all the information you need to do it,

Nicolas Maujean


public class FTPClientPlus
   extends FTPClient {

   /**
    * Constructeur
    */
   public FTPClientPlus() {

       super();
   }

   /**
    * Recupere la taille du fichier
    *
    * @param pNomFichier
    *            Nom du fichier
    * @return Taille du fichier
    *
    * @throws IOException
    */
   public long getFileSize(String pNomFichier) throws IOException {

       int result = sendCommand("size " + pNomFichier,
                                null);

       if (result == 550 || result != FTPReply.FILE_STATUS) {

           return -1;
       }

       String[] resultString = getReplyStrings();

       return Long.parseLong(resultString[0].substring(4));
   }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message