locked
FTP download in RTM Professional edition

    Question

  • FTP download seems to work in RTM but towards the end of the download , expcetion is thrown at the below point.

    download->GetResponseInformation()->Headers->Size);

     Taking the response information. >GetResponseInformation seems to be null. Any comments?


    • Edited by its_me_here Monday, September 3, 2012 5:41 PM
    Monday, September 3, 2012 5:25 PM

All replies

  • Can you please provide more detail? What exactly is your code doing when you get here?

    It helps greatly if a request for help includes:

    • The overall goal
    • How it is being achieved, in as much detail as is necessary. Minimal code sufficient to reproduce the problem and clear repro steps are ideal
    • What is the expected behavior?
    • What is the actual behavior?

    --Rob

    Tuesday, September 4, 2012 11:30 PM
    Owner
  • Hi, Rob. Thanks for the reply. Please find the below inputs;

    1. Overall goal: To download an exe( more than around 100MB) from an ftp server

    2.I am trying to achieve this via background transfer(I am able to successfully download files from http server using background transfer)

    3. The actual behavour is when we obtain the response of the download, it thorws exception and the app crashes.I have commented in the code where the issue occurs.

    The below code will reproduce this scenario. This sample code is actually based on the background tranfer sample available in the Metro app samples collection. If we give an ftp download link in the download filename box in the app and start download, we will get the same error.

    Concurrency::cancellation_token_source* CancellationToken;

    CancellationToken = new cancellation_token_source();

    String^ DownloadLink = "ftp://myftplink/MyFile.exe";// just an example link.

    Windows::Storage::StorageFolder^ folder = ApplicationData::Current->LocalFolder; String^ file_name = "MyDownloadedFile.exe";// The file will be downloaded in this name.

    task<StorageFile^>(folder->CreateFileAsync(file_name, CreationCollisionOption::ReplaceExisting)) .

    then([this](StorageFile^ file)

    {

    BackgroundDownloader^ bd = ref new BackgroundDownloader( );

    if( bd )

    {

    DownloadOperation^ loader_op = bd->CreateDownload( ref new Uri(DownloadLink ), file );

    if( loader_op )

    {

    IAsyncOperationWithProgress<DownloadOperation^, DownloadOperation^>^ async; async = loader_op->StartAsync();

    if( async )

    {

    task<DownloadOperation^>(async, CancellationToken->get_token()).

    then([this] (DownloadOperation^ download)

    {

    ResponseInformation^ response = download->GetResponseInformation();

    // The exception occurs at just the above line( taking response information)

    // The reponse object seems invalid here.  May be because the ftp header is different from that of http( my guess)

    // The expected beviour is the header should be valid.

    if( 200 == response->StatusCode )

    {

    //Download is complete.

    }

    else

    {

    // download has failed. Do accordingly

    } }).

    then([this, loader_op] (task<void> previousTask)

    {

    try

    {

    previousTask.get();

    }

    catch (Exception^ ex)

    {

    }

    });

     }

    }

    });

    Try the above code with an ftp link . This works fine for http download links. I gather from the forums that background transfer is the way for ftp download. What change is to be mqde for this for ftp? If there is any other method , just inform. I tried this on VS 2012 RP on Win8 RTM. Is the error because of the difference between ftp and http download/message header structures?

    • Edited by its_me_here Wednesday, September 5, 2012 4:59 PM
    Wednesday, September 5, 2012 4:53 PM
  • I am using the below code for downloading a large file( more than 200 MB ) from an ftp server using background transfer. But the code throws exception at the specified section( comment added). the file is downloaded anyway..The same code works fine  for http download without any issues.

    Concurrency::cancellation_token_source* CancellationToken;

    CancellationToken = new cancellation_token_source();
    String^ DownloadLink = "ftp://myftplink/MyFile.exe";// just an example link.
    Windows::Storage::StorageFolder^ folder = ApplicationData::Current->LocalFolder; String^ file_name = "MyDownloadedFile.exe";// The file will be downloaded in this name.
    task<StorageFile^>(folder->CreateFileAsync(file_name, CreationCollisionOption::ReplaceExisting)) .
    then([this](StorageFile^ file)
    {
    BackgroundDownloader^ bd = ref new BackgroundDownloader( );
    if( bd )
    {
    DownloadOperation^ loader_op = bd->CreateDownload( ref new Uri(DownloadLink ), file );
    if( loader_op )
    {
    IAsyncOperationWithProgress<DownloadOperation^, DownloadOperation^>^ async;

    async = loader_op->StartAsync();
    if( async )
    {
    task<DownloadOperation^>(async, CancellationToken->get_token()).
    then([this] (DownloadOperation^ download)
    {
    ResponseInformation^ response = download- >GetResponseInformation();
    // The exception occurs at just the above line( taking response information)
    // The reponse object seems invalid here.  May be because the ftp header is different from that of http( my guess)
    // The expected beviour is the header should be valid.
    if( 200 == response->StatusCode )
    {
    //Download is complete.
    }
    else
    {
    // download has failed. Do accordingly
    } }).
    then([this, loader_op] (task<void> previousTask)
    {
    try
    {
    previousTask.get();
    }
    catch (Exception^ ex)
    {
    }
    });
      }
    }
    });
    Try the above code with an ftp link . This works fine for http download links. I gather from the forums that background transfer is the way for ftp download. What change is to be mqde for this for ftp? If there is any other method for ftp download , just inform. I tried this on VS 2012 RTM on Win8 RTM. Is the error because of the difference between ftp and http download/message header structures?

    Saturday, September 22, 2012 6:46 PM
  • The exception appears to be that you are dereferencing a null pointer (returned by GetResponseInformation). I'm not sure why exactly GetResponseInformation is returning null, but you should check for that before using it.

    Note that per the Transferring data in the background documentation only HTTP and HTTPS are supported:

    This feature supports file transfers using the HTTP and HTTPS protocols.

    BTW: it would be much easier if you would put your code in a code block so it can be readily cut & pasted for testing. A link to a repro project on SkyDrive would also be helpful.

    --Rob

    Sunday, September 23, 2012 3:15 AM
    Owner
  • Thank you Rob for your answer. In fact I have been following this thread for a while..If background transfer is not supported for FTP, then by what other methods can I download from ftp?

    Also the below link says background transfer is also used for FTP:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465399.aspx


    • Edited by its_me_here Sunday, September 23, 2012 9:23 AM
    Sunday, September 23, 2012 8:33 AM
  • You can use IXMLHttpRequest for FTP downloads.

    Jeff Sanders (MSFT)

    Monday, October 1, 2012 11:54 AM
    Moderator
  • Hi Jeff, thank you for the reply. I hope you meant IXMLHttpRequest and not IXMLHttpRequest2.

    Can you please point me some sample code as to how one can use this interface for downloading exes from ftp server?

    Monday, October 1, 2012 6:48 PM
  • I tried sending request to an ftp site by the below code using IXMLHttpRequest2 interface. But I am getting the error "The URL is invalid" at the Open() method of IXMLHttpRequest2 . Here is the code:m_HttpRequest is of type IXMLHttpRequest2 .

    HRESULT hrSend = CoCreateInstance(CLSID_FreeThreadedXMLHTTP60, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_HttpRequest)); if (SUCCEEDED(hrSend)) { ComPtr<IXMLHTTPRequest2Callback> CallBack = Microsoft::WRL::Details::Make<CallBackHandler>( ref new XHRDataReceived(this, &MainPage::OnData), ref new XHRFailed(this, &MainPage::OnFailed), ref new XHRHeaders( this,&MainPage::Send ), ref new XHRSet ( this, &MainPage::OnReceive ), ref new XHRDisp( this,&MainPage::Disp ) );

    // Getting :URL is invalid " in the below line. hrSend = m_HttpRequest->Open( L"GET", L"ftp://ftp.freebsd.org/pub/FreeBSD/doc/README.txt", CallBack.Get(), nullptr, nullptr, nullptr, nullptr); if (SUCCEEDED(hrSend)) { if (SUCCEEDED(hrSend)) { hrSend = m_HttpRequest->Send(NULL,0); } } } if (FAILED(hrSend)) { }

    but it works fine with an http sites. I heard from other sources also that this interface can be used for FTP transfer. What is wrong in the way I have specified the ftp url?




    • Edited by its_me_here Tuesday, October 2, 2012 7:00 PM
    Tuesday, October 2, 2012 6:57 PM
  • I tried sending request to an ftp site by the below code using IXMLHttpRequest2 interface. But I am getting the error "The URL is invalid" at the Open() method of IXMLHttpRequest2 . Here is the code:  m_HttpRequest  is of type IXMLHttpRequest2 .

    HRESULT hrSend = CoCreateInstance(CLSID_FreeThreadedXMLHTTP60, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_HttpRequest));
     
     if (SUCCEEDED(hrSend))
     {                    
    	  ComPtr<IXMLHTTPRequest2Callback> CallBack = Microsoft::WRL::Details::Make<CallBackHandler>(
    	  ref new XHRDataReceived(this, &MainPage::OnData),  
    	  ref new XHRFailed(this, &MainPage::OnFailed),
    	  ref new XHRHeaders( this,&MainPage::Send ),
    	  ref new XHRSet ( this, &MainPage::OnReceive ),
    	  ref new XHRDisp( this,&MainPage::Disp )
    	  );   
    
    		// Getting :URL is invalid "  in the below line.
    	  hrSend = m_HttpRequest->Open( L"GET", L"ftp://ftp.freebsd.org/pub/FreeBSD/doc/README.txt", CallBack.Get(), nullptr, nullptr, nullptr, nullptr);
      
    	  if (SUCCEEDED(hrSend))
    	  {
    	   if (SUCCEEDED(hrSend)) 
    	   { 
    		hrSend = m_HttpRequest->Send(NULL,0);
    	   }
    	  }
      
     }

    But it works fine with an http sites. I heard from other sources also that this interface can be used for FTP transfer as well as http. What could be wrong here?
    Wednesday, October 3, 2012 1:11 AM
  • Hi Its,

    After looking at this further, I believe that interface only supports HTTP and HTTPS.  I will have to confirm this.  Sorry for sending you the wrong direction if that is the case!

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, October 3, 2012 12:11 PM
    Moderator