I have the following Java code for FTPing files. When the file errors out (happens if there is no source file to pull) I get a zero-byte file in the destination. I want to kill that zero-byte file, but this code does not do it.
Any ideas?
Also, my file to delete is fully qualified with the path & filename...Code:public void doFTPGet() throws Exception { FtpClient fcMyFtp = new FtpClient(); fcMyFtp.openServer(this.getHOST()); fcMyFtp.login(this.getUID(), this.getPW()); // reading a file: if(this.IS_BINARY) { System.out.println("Getting Binary"); fcMyFtp.binary(); } else { System.out.println("Getting ASCII"); fcMyFtp.ascii(); } try { byte buffer[] = new byte[1000]; int len; FileOutputStream fos = new FileOutputStream( this.getLOCAL_FILE() ); TelnetInputStream tis = fcMyFtp.get(this.getREMOTE_FILE()); while( (len = tis.read(buffer)) != -1 ) { fos.write(buffer,0,len); //System.out.println("Reading"); } tis.close(); fos.close(); } catch( IOException e ) { e.printStackTrace(); //Delete the file File filepath = new File(this.getLOCAL_FILE()); filepath.delete(); throw new Exception(e.toString()); } System.out.println("Done!"); }//End doFTPGet




Reply With Quote