示例#1
0
        private async void DoDownloadOrUpload(bool isDownload)
        {
            Uri uri = new Uri(HostTextBox.Text);

            StatusTextBlock.Text = "Connecting.";

            FtpClient client = new FtpClient();
            await client.ConnectAsync(
                new HostName(uri.Host),
                uri.Port.ToString(),
                UserTextBox.Text,
                PassTextBox.Text);

            if (isDownload)
            {
                StatusTextBlock.Text = "Downloading.";

                byte[] data = await client.DownloadAsync(uri.AbsolutePath);

                ContentTextBox.Text = Encoding.UTF8.GetString(data, 0, data.Length);
            }
            else
            {
                StatusTextBlock.Text = "Uploading.";

                byte[] data = Encoding.UTF8.GetBytes(ContentTextBox.Text);

                await client.UploadAsync(uri.AbsolutePath, data);
            }

            StatusTextBlock.Text = "Done.";
        }