What kind of error do you receive (take a look at downloaded file) ? Most likely you incorrectly sign outgoing request. Please take a look at this document: Signing and Authenticating REST Requests.
I would also recommend you to carefully read Amazon S3 REST API to understand how you should operate with S3 buckets / objects.
Hope it helps you !