I'm trying to develop a function that downloads a file in a FTP directory. I try this way
static void descargarFic(string ficFTP, string user, string pass, string dirLocal)
{
Library.WriteErrorLog(ficFTP + " -> " + dirLocal);
try
{
WebClient client = new WebClient();
client.Credentials = new NetworkCredential(user, pass);
client.DownloadFile(ficFTP, dirLocal);
Library.WriteErrorLog("Done");
client.Dispose();
}
catch(Exception e)
{
Library.WriteErrorLog(e.Message);
}
}
The WriteErrorLog write on a file the string passed. So, I'm calling that function in this way:
descargarFic("ftp://something-here/incoming/file.xml.gz", "anonymous", "password", #"C:\folder1\file.xml.gz");
But I receive the exception Exception during a WebClient request for a FTP download when I try to download it.
I'm pretty sure that it's some kind of problem with the URI, but I didn't realize where it is.
EDIT: Using Library.WriteErrorLog(e.InnerException);
The exception given is
The given access path's format is not supported.
Related
I use an javascript picker to get file from my google drive, it's work well and i get then download url and acces_token from my drive
I would like to download bytes array from this file from my server, then i path the url and acces_token to it (with ajax), no problem
on server i would get data with this code (it's worked !!!)
public void DownloadFile(string url, string AccessToken)
{
try
{
byte[] BB;
using (WebClient wc = new WebClient())
{
wc.Headers.Add("Authorization", "Bearer " + AccessToken);
BB = wc.DownloadData(url);
}
}
catch (Exception ex)
{
throw ex;
}
}
now i get an 403 error ??
url are like "https://content.googleapis.com/drive/v2/files.....?key=mykey....."
what's changed on google server ?
thanks
If you want to download a file using the Drive API and setting the access token in the header, you have to do it by calling this url:
https://www.googleapis.com/drive/v2/files/[file-Id]?alt=media
As it's told in the Response section in the Files: get endpoint. It's really important the url parameter alt=media in order to make it work. Don't use an API Key.
I want to download Images from SharePoint Online site . Here is my code it will give webclient Exception.
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
var credentials = new SharePointOnlineCredentials(username, securedPassword);
DownloadFile(url, credentials, "https://damasjewellery.sharepoint.com/:i:/r/Products/Catalogue%20Images/BDR-001-NA-RG-X-0.JPG?csf=1&e=FclkOs");
DownloadFile Method Contains Webclient Object And Its DownloadFIle method. When I pass Url and path of Particular Images It will Give me an exception .
using (var client = new WebClient())
{
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.Headers.Add("User-Agent: Other");
client.Credentials = credentials;
client.DownloadFile(webUrl, fileRelativeUrl);
}
A WebClient Exception usually means there's some kind of connection issue. Either the server returned a 404, the server timed out, there's no internet connection, or you're having a permissions issue.
*Edit: Realized the exception being thrown was already in the question.
Try swapping url to uri.
public void DownloadFile(
Uri address,
string fileName
)
I have created a virtual directory with read and write access to everyone on Machine B. I am running web application 1 on Machine A. Now the requirement is to upload a file to remote http location from this web application. Machine A web application i is configured with anonymous authentication.
i am not able to implement the above requirement successfully. Please suggest whether this approach is correct or not?
public override bool UploadFile()
{
byte[] postData;
try
{
postData = this.FileData;
using (WebClient client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.UploadData(this.UrlString, "PUT", postData);
}
return true;
}
catch (Exception ex)
{
throw new Exception("Failed to upload", ex.InnerException);
}
}
i have tried the example given in the below location
http://code.msdn.microsoft.com/CSASPNETRemoteUploadAndDown-a80b7cb5
unfortunately i could not able to make it work. I am using IIS7 on both machine A & B
Please suggest.
I have a code like this in my local exe to upload a file in a certain url:
private static void SaveTToWeb()
{
try {
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadFile("www.something.com/uploadreceiver.aspx", "POST", "text.txt");
client.Dispose();
myFile = null;
urlForUpload = null;
}
catch (Exception err) { Console.write("error: " + err.Message(); }
}
my question is, in the server side "uploadreceiver.aspx" page, what code should i use to actually receive the file? thank you!
The CSASPNETRemoteUploadAndDownload sample shows how to upload files to and download files from remote server in an ASP.NET application.
You can download the sample code or read more here http://code.msdn.microsoft.com/CSASPNETRemoteUploadAndDown-a80b7cb5
I am a beginner in WP7. I need to send a request to the server. The request included username, password and an authentication header. If succeeded I get some data from the server in xml form. How can I send the request to the server?
You certainly shouldn't be using the WebClient class as this executes on the UI thread so will cause the app to lock, instead look at the HttpWebRequest class.
There is a good example here: http://www.codeproject.com/Articles/156610/WP7-WebClient-vs-HttpWebRequest
To add headers, you can access the HttpWebRequest.Headers property so you could add a basic authorization header as per this http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html
Alternatively, you can use the HttpWebRequest.Credentials property (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.credentials.aspx for more details)
You'd want to check the status code of the response to verify if the authentication was successful, so you'd access the HttpWebResponse.StatusCode property and see if if it is 401 (unauthorized).
Try this one:
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += (s, e) =>
{
string xml = e.Result;
};
webClient.DownloadStringAsync(new Uri("http://..." + your params));
void SendRequest()
{
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://somesite.com/webservice"));
wc.DownloadStringCompleted +=DownloadStringCompleted;
}
void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Debug.WriteLine("Web service says: " + e.Result);
}