Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将图像上载到windows phone上的FTP服务器_C#_Windows_Windows Phone 8_Ftp_Webclient - Fatal编程技术网

C# 将图像上载到windows phone上的FTP服务器

C# 将图像上载到windows phone上的FTP服务器,c#,windows,windows-phone-8,ftp,webclient,C#,Windows,Windows Phone 8,Ftp,Webclient,请帮忙!我什么都试过了,不知道还能做什么。我只想将用户从其库中选择的图像上载到我的websever 我已经有了一个使用webclient上传到url的代码 private void OnChoosePicturel(object sender, RoutedEventArgs e) { PhotoChooserTask task = new PhotoChooserTask(); task.Completed += task_Co

请帮忙!我什么都试过了,不知道还能做什么。我只想将用户从其库中选择的图像上载到我的websever

我已经有了一个使用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");
        }
private void OnChoosePicturel(对象发送方、路由目标方)
{
PhotoChooserTask=新的PhotoChooserTask();
task.Completed+=task_Completed;
task.Show();
}
私有无效任务_已完成(对象发送方,照片结果e)
{
if(e.TaskResult!=TaskResult.OK)
返回;
const int BLOCK_SIZE=4096;
Uri=新的Uri(“URL”);
WebClient wc=新的WebClient();
NetworkCredential g=新的NetworkCredential();
g、 UserName=“UserName”;
g、 Password=“Password”;
wc.g=g;
wc.AllowReadStreamBuffering=true;
wc.AllowWriteStreamBuffering=true;
尝试
{
//写流打开时要做什么
wc.OpenWriteCompleted+=(s,args)=>
{
使用(BinaryReader br=新的BinaryReader(e.ChosenPhoto))
{
使用(BinaryWriter bw=新的BinaryWriter(args.Result))
{
长b计数=0;
long fileSize=e.ChosenPhoto.Length;
字节[]字节=新字节[块大小];
做
{
字节=br.ReadBytes(块大小);
bCount+=字节。长度;
写入(字节);
}而(b计数<文件大小);
}
}
};
}
捕获(异常t)
{
}
//写作完成后要做什么
wc.WriteStreamClosed+=(s,args)=>
{
MessageBox.Show(“发送完成”);
};
//写入WebClient
OpenWriteAsync(uri,“STOR”);
}

问题是,
webclient
类仅适用于
“http”
url,但我需要将文件连接并上载到
“ftp”
url。我该怎么做?我什么都试过了。什么都不管用。

你能详细说明你得到了什么样的例外情况吗。此外,您可以使用StreamSocket连接到ftp服务器。@Ritesh Khichadia,但ftp服务器需要身份验证。如何使用streamsocket对自己进行身份验证?服务器如何知道如何读取文件以及如何命名?