本文介绍了将所有文件从我的计算机写入到Ftp服务器(另一台计算机)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

嘿,我试图将所有文件从本机上的目录复制到FTP服务器上的另一个目录(FTP服务器上不存在要将文件复制到的文件夹)...我遇到了异常---- > 无法发送具有这种动词类型的内容主体..流reqStream = request.GetRequestStream();

这是我的代码,请帮我解决问题.

Hello Guys,

Hey im trying to copy all the files from a directory on my machine to another directory on the FTP server(The folder to which i want to copy my files doesnot exist on the ftp server)...Im getting an exception ----> Cannot send a content-body with this verb-type.Here---> Stream reqStream = request.GetRequestStream();

Here is my code please help me out fellas.

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://192.168.1.119/images");
 request.Credentials = new NetworkCredential("Rahul Middha","jkd");
request.Method = WebRequestMethods.Ftp.MakeDirectory;
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;


            DirectoryInfo di = new DirectoryInfo("C:\\Datacap\\Demo\\images");
            FileInfo[] files=null;
            if (di.Exists)
            {
                files = di.GetFiles("*.TIF");
            }
            FileStream fs = null;
            int buffLength = 2048;
            byte[] buff = new byte[buffLength];
            foreach (FileInfo fi in files)
                {

                    fs = fi.OpenRead();
                    fs.Read(buff, 0, buff.Length);
                }

            fs.Close();

            Stream reqStream = request.GetRequestStream();
            reqStream.Write(buff, 0, buff.Length);
            reqStream.Close();



[Edit(zorgoz):添加了代码块,删除了喊叫声]



推荐答案


这篇关于将所有文件从我的计算机写入到Ftp服务器(另一台计算机)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 10:35