简体   繁体   English

如何使用我的 Xamarinapp 从 FTP 服务器下载文件?

[英]How can I download a file from an FTP server with my Xamarinapp?

I'm new to Xamarin development.我是 Xamarin 开发的新手。 I hope that you can resolve my problem in a simple mode.我希望您能以简单的方式解决我的问题。

I have a cross-platform app developed with Xamarin.我有一个使用 Xamarin 开发的跨平台应用程序。 In one page of the app I want to give the possibility to download a file (pdf document) when the user taps a button.在应用程序的一个页面中,我想在用户点击按钮时提供下载文件(pdf 文档)的可能性。 How can I do it?我该怎么做?

The file is hosted in an FTP server.该文件托管在 FTP 服务器中。

Please, if you can, give me a simple solution.如果可以的话,请给我一个简单的解决方案。 Thanks.谢谢。

This is my button in page.xaml这是我在页面中的按钮。xaml

   <StackLayout BackgroundColor="#2B2B2B" HeightRequest="60" Orientation="Horizontal" Padding="0" Margin="0" MinimumWidthRequest="-1">
        <ImageButton VerticalOptions="Center" HorizontalOptions="Start" Source="pdf.png" HeightRequest="50" WidthRequest="50" Margin="10,0,0,0" ></ImageButton>
        <Button VerticalOptions="Center" TextColor="White"  BackgroundColor="Transparent" FontSize="20" FontAttributes="Italic" Text="Scarica il PDF"></Button>
</StackLayout>

The System.Net.WebClient can be used cross platform for FTP calls. System.Net.WebClient可以跨平台用于 FTP 调用。 Here you can find sample code: FtpCloudStorageClient.cs在这里您可以找到示例代码: FtpCloudStorageClient.cs

Have a look at the DownloadFileAsync() function.看看DownloadFileAsync() function。 If you don't need SSL support, you can directly create a WebClient instead of the derrived CustomFtpWebClient .如果您不需要 SSL 支持,您可以直接创建WebClient而不是派生的CustomFtpWebClient It would look something like this (untested):它看起来像这样(未经测试):

public override async Task<byte[]> DownloadFileAsync(string ftpUrl, string username, string password)
{
    byte[] responseData;
    using (WebClient webClient = new WebClient())
    {
        webClient.Credentials = new NetworkCredential(username, password);
        responseData = await webClient.DownloadDataTaskAsync(ftpUrl);
    }
    return responseData;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 .net 控制台应用程序从 ftp 服务器下载名称中包含希伯来语字符的文件? - How can I download a file with Hebrew characters in its name from an ftp server via .net console application? Xamarin PCL-如何将文件上传到FTP服务器或从FTP服务器下载文件? - Xamarin PCL - How can I upload/download a File to/from a FTP Server? 如何使用ftp服务器上传文件? - How I can upload file with ftp server? 如何使用foreach()和ftpwebrequest优化我的FTP下载? - How Can I optimize my FTP Download using foreach() and ftpwebrequest? 从 FTP 服务器下载最新文件 - Download the latest file from an FTP server 从Metro应用程序中的ftp服务器下载文件 - Download file from ftp server in metro application 如何从一个FTP下载文件,然后将文件上传到另一个FTP? - How to Download file from one FTP and then Upload file to different FTP? 如何从sharepoint服务器下载excel文件? - How can i download an excel file from sharepoint server? 如何从FTP服务器下载ZipFile - How to download ZipFile From FTP server 从FTP服务器下载文件:远程服务器返回错误:(425)无法打开数据连接 - Download a file from the FTP server: The remote server returned an error: (425) Can't open data connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM