在C#里怎么把一个文本框里输入的内容保存成一个文件,同时再上传到FTP服务器啊?
他这个FTP服务器不能创建文件,我快晕死了
怎么办啊
就是跟发邮件一样,只是把文本框里的内容在服务器上保存成一个文件
各位大哥大姐救救我吧

解决方案 »

  1.   

    public void Upload(string filename)
            {
                FileInfo fileInf = new FileInfo(filename);
                pubFile File_text = new pubFile("", filename); 
                //string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
                FtpWebRequest reqFTP;
                try
                {
                    // 根据uri创建FtpWebRequest对象 
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strURI));
                    //reqFTP.UsePassive = false;
                    // ftp用户名和密码
                    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                    //reqFTP.ContentType = "application/x-www-form-urlencoded";                // 默认为true,连接不会被关闭
                    // 在一个命令之后被执行
                    //reqFTP.KeepAlive = false;
                    reqFTP.UsePassive = false;
                    
                    // 指定执行什么命令
                    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;                // 指定数据传输类型
                    reqFTP.UseBinary = true;
                    //reqFTP.EnableSsl = true;
                    // 上传文件时通知服务器文件的大小
                    reqFTP.ContentLength = fileInf.Length;                // 缓冲大小设置为2kb
                    int buffLength = 2048;                byte[] buff = new byte[buffLength];
                    int contentLen;                // 打开一个文件流 (System.IO.FileStream) 去读上传的文件
                    FileStream fs = fileInf.OpenRead();                // 把上传的文件写入流
                    //FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();                //File_text.Write(DateTime.Now.ToString() + response.StatusDescription);
                    //File_text.Write(DateTime.Now.ToString() + response.StatusCode.ToString());
                    Stream strm = null;
                   
                    strm = reqFTP.GetRequestStream();
                                    // 每次读文件流的2kb
                    contentLen = fs.Read(buff, 0, buffLength);                // 流内容没有结束
                    while (contentLen != 0)
                    {
                        // 把内容从file stream 写入 upload stream
                        strm.Write(buff, 0, contentLen);
                        contentLen = fs.Read(buff, 0, buffLength);
                    }
                    File_text.WriteErrorLine(DateTime.Now.ToString() + "成功");                // 关闭两个流
                    strm.Close();
                    fs.Close();
                }
                
                catch (Exception ex)
                {
                    File_text.WriteErrorLine(DateTime.Now.ToString() + "\nUpload Error:" + ex.Message);
                }
                
            }
      

  2.   

    pubFile ,FtpWebRequest都是哪个命名空间里的啊
      

  3.   

    哥哥啊,我要2003的代码FtpWebRequest是2005里的类啊
      

  4.   

    just Process.Start("ftp.exe")
      

  5.   

    shrinerain(圣影雨) 是叫你直接调用ftp这个exe要上传?有FileUpload控件啊,直接用不就可以了,为什么要用ftp呢?