locked
FTP file download

    Question

  • I am trying to download an exe file from ftp server using background transfer  . The file is about 200 mb. I use the following code for the download:

      Windows::Storage::StorageFolder^ folder = ApplicationData::Current->LocalFolder;
      file_name = "Trial.exe";  
      task<StorageFile^>(folder->CreateFileAsync(file_name, CreationCollisionOption::ReplaceExisting))
      .then([this](StorageFile^ file)
      {
       wchar_t msgbuffer[1024] = {0};
       BackgroundDownloader^  bd = ref new BackgroundDownloader( );
       DownloadOperation^ loader_op = bd->CreateDownload( ref new Uri("ftp site name"), file );

       task<DownloadOperation^>(loader_op->StartAsync()).then([this](DownloadOperation^ opCallback) -> DownloadOperation^
       { 
        if (opCallback->Progress.HasRestarted)
        {
         OutputDebugString( L"Restarted" );
        } 

        if (opCallback->Progress.HasResponseChanged)
        {
         OutputDebugString( L"Response Changed" );
        }
        return opCallback;

       }).then([this,&file](DownloadOperation^ opResponse)
       {
        wchar_t msgbuffer[1024] = {0};
        ResponseInformation^ response = opResponse->GetResponseInformation();      
        if (response)
        {
         if( 200 == response->StatusCode )
         {
           //OK
         }
         else
         {
          // Failed

         }
        }   
       });
      }); 

    It does not seem to work. Exception is thrown at the section Progress.HasResponseChanged. I m able to download the same file from an http server using the same code. I tried downloading this file from the ftp server using background transfer sample app. But here also the code breaks in exception at the HasResponseChanged section. What  is wrong with my code? Can't this be used for ftp download? I tried to download the exe with ixmlhttprequest2 with GET as method. But here I am getting error in the OnError() override of the callback.

    Most of the time what happens is that the app is running but the download does not happen and the exception does not occur at all!!

    Or at least  point me some samples where there if ftp download

    Monday, June 18, 2012 6:34 AM

All replies

  •  

    Hi,

     

    I hope this sample code can help you

    http://code.msdn.microsoft.com/windowsapps/Background-Transfer-Sample-d7833f61#content

     

    Background Transfer sample, this sample is based on Windows 8 Release Preview.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 12:57 PM
  • The sample throws exception in the below section as I already mentioned in the post.

    Scenario1::DownloadProgress()
    {
     if (download->Progress.HasResponseChanged)
     {

     }

    }

    download->GetResponseInformation() returns null so that it throws exception. I tried validating the ResponsiInformation object. The app runs but it never seems to download. Download is not happening. Someone has already pointed this out in the Q AND A section of the sample .What other step is to be done? I am using release preview.


    Tuesday, June 19, 2012 5:29 AM
  • Hi its_me_here,

    If you read the documentation on background transfers you will see that the BackgroundTransfer classes transfer using Http: and https: protocols. They don't use ftp.

    --Rob

    Tuesday, June 19, 2012 6:16 AM
    Owner
  • Then by what method or API can I download a file from ftp? I tried using ixmhttprequest2 but that doesnt work..From the name of the interface i think that too works for http only...Is there any way I can download from ftp? I read somewhere that you can create ftp clients in metro
    Tuesday, June 19, 2012 6:47 AM
  • The Release Preview doesn't have built in ftp functionality. You would need to implement this yourself. BackgroundTransfer would be the way, but there were known bugs with it.

    --Rob

    Thursday, June 21, 2012 10:12 PM
    Owner
  • Hi,

       Does that mean I have to go for some sockets/ streams to implement it? And why do we have to implement it ourselves ?  Since there is ample support for http(s), shouldnt there be support for ftp as well in release preview?


    Friday, June 22, 2012 3:51 AM
  • This is unfortunately not working in the Release Preview as Rob mentioned. This is a known issue being worked on at this time.

    David Lamb

    Friday, June 22, 2012 7:16 PM
    Moderator
  • The Release Preview doesn't have built in ftp functionality. You would need to implement this yourself. BackgroundTransfer would be the way, but there were known bugs with it.

    --Rob


    maybe I need to go on trying to implement ftp functionality by socktet. About the way,do you have any references? may you provide it to me?
    Monday, June 25, 2012 11:20 AM
  • maybe I need to go on trying to implement ftp functionality by socktet. About the way,do you have any references? may you provide it to me?
    Monday, June 25, 2012 11:36 AM
  • This is unfortunately not working in the Release Preview as Rob mentioned. This is a known issue being worked on at this time.

    David Lamb

    Hi David,

    Can you confirm if BackgroundDownloader now works fine with FTP under RTM ?

    Thanks!


    Thomas Lebrun [MVP] - Windows 8 / Windows Phone / WPF / SL: http://blog.thomaslebrun.net

    Wednesday, August 08, 2012 8:04 PM
  • BackgroundDownloader doesn't work fine with FTP under RTM. It behaves in the same way as in CustomerPreview, broken for most of the ftp sites.
    Saturday, September 22, 2012 2:01 PM
  • What is the next step? What is the sure method of FTP download in RTM?
    Thursday, October 04, 2012 6:47 PM
  • It seems the ResponseInformation is always null in the case of ftp download unlike in the case of http download.

    So , referring to the code I have pasted in the post further above, I think if ResponseInformation is null, then we can get the file size using DownloadOperation::ResultFile property. If the file has been fully downloaded I think its size will be valid. Is size is still zero can we assume the download failed?


    • Edited by its_me_here Thursday, October 04, 2012 7:32 PM
    Thursday, October 04, 2012 7:13 PM