Download files from SharePoint C # – Access is denied

I have a problem with downloading files from Sharepoint via C #.

I have this code:

const string username = "";
const string password = "password";
const string url = "";
var securedPassword = new SecureString ();
foreach (var c in password.ToCharArray ()) securedPassword.AppendChar (c);
var credentials = new SharePointOnlineCredentials (user name,

DownloadFile (url, credentials, "/ Shared Documents / Report.xslx");

private static void DownloadFile (webUrl string, ICredentials credentials,
string fileRelativeUrl)
using (client var = new WebClient ())
client.Headers.Add ("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.Headers.Add ("User Agent: Other");
client.Credentials = identification information;
client.DownloadFile (webUrl, fileRelativeUrl);

But when I try to run it, this error appears:
enter the description of the image here

I can access Google Chrome without any problem and download all the files.

Someone knows what permissions need to be allocated in Sharepoint? And is the problem of sharepoint or server from which the query is executed?

Thank you!