0

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

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

 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"url,但我需要连接并将文件上传到"ftp"url。我该怎么做呢?我什么都试过了。没有任何效果。

4

0 回答 0