@Override
	@Command
	public Response download(String filename) throws IOException
	{
		File f = new File(directory, filename);
		if(f.exists())
		{
			f.delete();
		}
		DownloadTicketRequest request = new DownloadTicketRequest(filename);
		
		this.sendToServer(request);
		
		try
		{
			Response r = (Response) objectInput.readObject(); 
			if(r instanceof MessageResponse)
			{
				return r;
			}
			if(r instanceof DownloadTicketResponse)
			{
				DownloadTicketResponse response = (DownloadTicketResponse)r;
				DownloadTicket ticket = response.getTicket();

				Socket downloadSocket = new Socket(ticket.getAddress(), ticket.getPort());
				ObjectOutputStream oos = new ObjectOutputStream(downloadSocket.getOutputStream());
				oos.flush();
				ObjectInputStream ois = new ObjectInputStream(downloadSocket.getInputStream());
				DownloadFileRequest fileRequest = new DownloadFileRequest("",ticket);

				oos.writeObject(fileRequest);
				oos.flush();
				Response fileResponse = (Response) ois.readObject();
				if(fileResponse instanceof MessageResponse)
				{
					return fileResponse;
				}
				else if(fileResponse instanceof DownloadFileResponse)
				{
					DownloadFileResponse downloadFile = (DownloadFileResponse)fileResponse;
					String text = new String(downloadFile.getContent());
					File downloaded = new File(directory, filename);
					downloaded.createNewFile();

					PrintWriter out = new PrintWriter(downloaded);
					out.println(text);
					out.flush();
					out.close();
					oos.close();
					ois.close();
					downloadSocket.close();
					return downloadFile;
				}
			}
		} 
		catch(EOFException eof)
		{
			shell.writeLine("Socket closed unexpectedly");
			exit();
		}
		catch(SocketException se)
		{
			shell.writeLine("Socket closed unexpectedly.");
			exit();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		return null;
	}