locked
Exception thrown while uploading file on FTP server from Windows Phone 8 RRS feed

  • Question

  • I want to upload a video file on FTP server, my all search results ended to MSDN managzine article Adding FTP Support in Windows Phone 8. It has awesome example & library. I tried 2 FTP URLs, one is Mozilla repository & another is my confidential URL. Nothing worked for me but throws exception. I tried my FTP URL in an app called File Downloader, it worked correctly. Expcetion details & output windows log is given below.

    Thus, any one can suggest me what should I do changes in that library? Is there another working library available or any other way to upload file to FTP?

    Exception is thrown in file FtpClient.cs, event FtpClientSocket_DataReceived(...), at line "await PrepareDataChannelAsync(Response);" [Line # 253]
    
    ftp.mozilla.org
    
    System.Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (Exception from HRESULT: 0x8007274C)
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WinPhoneFtp.FtpService.FtpClient.<PrepareDataChannelAsync>d__2b.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WinPhoneFtp.FtpService.FtpClient.<FtpClientSocket_DataReceived>d__3.MoveNext()
    
    Output log
    
    FTP Server IP Address: ftp.mozilla.org with port 21
    FTP Command Channel Initailized
    FTPServer -> 220-
    220-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
    220-
    220-   Notice: This server is the only place to obtain nightly builds and needs to
    220-   remain available to developers and testers. High bandwidth servers that
    220-   contain the public release files are available at ftp://releases.mozilla.org/
    220-   If you need to link to a public release, please link to the release server,
    220-   not here. Thanks!
    220-
    220-   Attempts to download high traffic release files f
    FTPServer -> rom this server will get a
    220-   "550 Permission denied." response.
    220 
    FTPClient -> USER anonymous
    FTPServer -> 331 Please specify the password.
    FTPClient -> PASS m@m.com
    FTPServer -> 230-
    230-   ftp.mozilla.org / archive.mozilla.org - files are in /pub/mozilla.org
    230-
    230-   Notice: This server is the only place to obtain nightly builds and needs to
    230-   remain available to developers and testers. High bandwidth servers that
    230-   contain the public release files are available at ftp://releases.mozilla.org/
    230-   If you need to link to a public release, please link to the release server,
    230-   not here. Thanks!
    230-
    230-   Attempts to download high traffic release files f
    FTPClient -> PWD
    FTPServer -> rom this server will get a
    230-   "550 Permission denied." response.
    230 Login successful.
    FTPClient -> PASV
    FTPServer -> 257 "/"
    FTPServer -> 227 Entered Passive Mode (63,245,215,46,199,76)
    FTP Data Channel IPAddress: 63.245.215.46, Port: 50951
    A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
    An exception of type 'System.Exception' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
    A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
    
    ========================================================================================================================
    
    Confidential FTP URL which required authentication
    
    System.Exception: No connection could be made because the target machine actively refused it. (Exception from HRESULT: 0x8007274D)
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WinPhoneFtp.FtpService.FtpClient.<PrepareDataChannelAsync>d__2b.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WinPhoneFtp.FtpService.FtpClient.<FtpClientSocket_DataReceived>d__3.MoveNext()
    
    Output log
    
    FTP Server IP Address: --CONFIDENTIAL-- with port 21
    FTP Command Channel Initailized
    FTPServer -> 220 (vsFTPd 2.0.5)
    FTPClient -> USER --CONFIDENTIAL--
    FTPServer -> 331 Please specify the password.
    FTPClient -> PASS --CONFIDENTIAL--
    FTPServer -> 230 Login successful.
    FTPClient -> PWD
    FTPClient -> PASV
    FTPServer -> 257 "/"
    FTPServer -> 227 Entering Passive Mode (173,193,219,177,156,29)
    FTP Data Channel IPAddress: 173.193.219.177, Port: 39938
    A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
    An exception of type 'System.Exception' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
    A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll

    Below given code works on Windows 8 but throws NotSupportedException on Windows Phone 8

    var ftpURL = "ftp://ftp.url.com";
    var request = WebRequest.Create(ftpURL + "/" + file_name.ext);
    request.Credentials = new NetworkCredential("uname", "pwd");
    request.Method = "STOR";
    
    byte[] fileBytes = null;
    using (var stream = await objStorageFile.OpenReadAsync())
    {
        fileBytes = new byte[stream.Size];
        using (var reader = new DataReader(stream))
        {
            await reader.LoadAsync((uint)stream.Size);
            reader.ReadBytes(fileBytes);
        }
    }
    
    var requestStream = request.BeginGetRequestStream(async a =>
    {
        var requestStreamEnd = request.EndGetRequestStream(a);
        await requestStreamEnd.WriteAsync(fileBytes, 0, fileBytes.Length);
        await requestStreamEnd.FlushAsync();
    }, request);
    
    var respo = request.BeginGetResponse(b =>
    {
        var res = request.EndGetResponse(b);
        var aa = res.Headers;
    }, null);
    

    • Edited by Xyroid Thursday, April 24, 2014 8:28 AM
    Thursday, April 24, 2014 6:56 AM

All replies

  • In Windows Phone, you can't create a WebRequest using a FTP Uri scheme.  The NotSupportedException is thrown from there, correct? (Line 2 in your lowest sample in your post)

    Darin R.

    Thursday, April 24, 2014 5:33 PM
  • OK, but how can I use that library which is in MSDN magazine article, forget about WebRequest?
    Friday, April 25, 2014 5:26 AM
  • Ok, maybe I jumped the gun. The second code is windows 8 ftp using WebClient, the first is a log output of Windows Phone 8.

    Can you post the code for the Windows Phone 8 that uses the FTPClient from the MSDN article - the exact code that creates the log entries?


    Darin R.

    Friday, April 25, 2014 1:36 PM
  • I found exception in the sample code of that article itself. You can download from here. I can see some apps on store already which allows FTP access, file upload/download etc. So I hope that library should work any how.
    Friday, April 25, 2014 6:17 PM