I try to upload an image (choosen by FileOpenPicker) but it doesn't work.
My code:
var openpicker = new FileOpenPicker();
openpicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openpicker.FileTypeFilter.Add(".jpg");
openpicker.FileTypeFilter.Add(".png");
var file = await openpicker.PickSingleFileAsync();
var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
PasswordCredential pw = new PasswordCredential();
pw.Password = "mypw";
pw.UserName = "user";
uploader.ServerCredential = pw;
uploader.Method = "POST";
var uri = new Uri("ftp://myaddress/Directory/");
var str = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
await uploader.SetSourceStreamAsync(str);
uploader.SetRequestHeader("Filename", "image2.jpg");
var upload = uploader.CreateUpload(uri);
var result = (await upload.StartAsync()).GetResponseInformation().StatusCode;
I get the following exception in the last line:
System.Runtime.InteropServices.COMException (0x80072EEF): Exception from HRESULT: 0x80072EEF
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificat‌​ion(Task task)
0x80072EEF is ERROR_INTERNET_LOGIN_FAILURE:
"The request to connect and log on to an FTP server failed."
Any ideas what I'm doing wrong?
I had the exact same problem. Even though this question is a bit old, I was directed here when searching for an answer.
i found that what is described here got it working for me. Basically BackgroundDownloader seems to fail when setting its ServerCredentials...
User contributions licensed under CC BY-SA 3.0