在Windows手机上将图像上传到FTP服务器

时间:2013-11-09 04:37:58

标签: c# windows windows-phone-8 ftp webclient

请帮忙!我已经尝试了一切,我不知道还能做什么。我只想将用户从其库中选择的图像上传到我的网络服务器。

我已经有一个使用webclient上传到网址的代码。

 private void OnChoosePicturel(object sender, RoutedEventArgs e)
        {
            PhotoChooserTask task = new PhotoChooserTask();
            task.Completed += task_Completed;
            task.Show();
        }
        private void task_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK)
                return;



            const int BLOCK_SIZE = 4096;

            Uri uri = new Uri("URL");

            WebClient wc = new WebClient();
            NetworkCredential g = new NetworkCredential();
            g.UserName = "USERNAME";
            g.Password = "PASSWORD";
            wc.Credentials = g;
            wc.AllowReadStreamBuffering = true;
            wc.AllowWriteStreamBuffering = true;

            try
            {
                // what to do when write stream is open
                wc.OpenWriteCompleted += (s, args) =>
                {
                    using (BinaryReader br = new BinaryReader(e.ChosenPhoto))
                    {
                        using (BinaryWriter bw = new BinaryWriter(args.Result))
                        {
                            long bCount = 0;
                            long fileSize = e.ChosenPhoto.Length;
                            byte[] bytes = new byte[BLOCK_SIZE];
                            do
                            {
                                bytes = br.ReadBytes(BLOCK_SIZE);
                                bCount += bytes.Length;
                                bw.Write(bytes);
                            } while (bCount < fileSize);
                        }
                    }
                };

            }
            catch(Exception t)
            {


            }

            // what to do when writing is complete
            wc.WriteStreamClosed += (s, args) =>
            {
                MessageBox.Show("Send Complete");
            };

            // Write to the WebClient
            wc.OpenWriteAsync(uri, "STOR");
        }

问题是,webclient类仅适用于"http"网址,但我需要连接并将文件上传到"ftp"网址。我该怎么做呢?我尝试了一切。什么都行不通。

0 个答案:

没有答案