Download files from bitbucket

I was asked to download a file (raw) from bitbucket repository and wrote an automation script using those files. Bitbucket exposed set of REST Web services for their repository using which we can integrate our application with bitbucket.

Steps to download files from bitbucket:

1. Need a HttpClient library , I opted for Apache CXF Client.


2. REST API documents . File Resource

public class GitClient {
	static String url = "";
	static String branch = "master";
	static String source = "/MavenWeb/src/main/resources/";
	String test = "/src/test/resources/";
	static String user = "username";
	static String password = "password";

	public static void usingWebClient() throws FileNotFoundException,IOException {

	private static void downloadFileFromBitBucket(String resource)
			throws IOException, FileNotFoundException {
		WebClient client = WebClient.create(url + branch + source + resource,user, password, null);
		Response r = client.accept("text/plain").get();
		System.out.println("reponse" + r.getStatus());
		IOUtils.copyLarge((InputStream) r.getEntity(), new FileOutputStream(new File("C:\\folder" + resource)));

	public static void main(String args[]) throws FileNotFoundException,IOException {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s