我用FTP类上传文件时只有文件名含有#号它就自动把#号和#号后的文件全删除了 是怎么回事呢

解决方案 »

  1.   

    你把上传的代码贴出来看看,#并不是ftp的一个命令,ftp的全部命令在这里:
    http://www.edu.cn/20010830/210045.shtml
      

  2.   

            string ftpServerIP;        string ftpUserID;        string ftpPassword;        //ftp文件上传 fileName:要上传的文件
            public void UpLoad(string fileName)
            {
                FileInfo fileInfo = new FileInfo(fileName);            string uri = "ftp://" + ftpServerIP + "/" + fileInfo.Name;            FtpWebRequest reqFTP;            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));// 根据uri创建FtpWebRequest对象            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//用户名和密码            reqFTP.KeepAlive = false;            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;// 指定执行什么命令            reqFTP.UseBinary = true; // 指定数据传输类型            reqFTP.ContentLength = fileInfo.Length;// 上传文件时通知服务器文件的大小            int buffLength = 2048;// 缓冲大小设置为2kb            byte[] buff = new byte[buffLength];            int contentLen;            FileStream fs = fileInfo.OpenRead();
                try
                {
                    Stream strm = reqFTP.GetRequestStream();                contentLen = fs.Read(buff, 0, buffLength);                while (contentLen != 0)
                    {
                        strm.Write(buff, 0, contentLen);                    contentLen = fs.Read(buff, 0, buffLength);
                    }
                    strm.Close();
                    fs.Close();            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Upload   Error ");
                }
                
            }        private void but_UpLoad_Click(object sender, EventArgs e)
            {
                if (this.txt_FTPAddress.Text != "" && this.listBox_FileName.Text != "")
                {
                    ftpServerIP = this.txt_FTPAddress.Text;
                    ftpUserID = this.txt_User.Text;
                    ftpPassword = this.txt_Pwd.Text;
                    this.UpLoad(this.listBox_FileName.Text);
                    MessageBox.Show("文件上传成功!");
                }
                else
                {
                    MessageBox.Show("FTP地址和文件名不能为空!请填写地址或者选择文件名!");
                }
            }        private void btn_OpenFileDialog_Click(object sender, EventArgs e)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = true;//设置属性为多选
                openFileDialog.ShowDialog();
                foreach (string fName in openFileDialog.FileNames)
                {
                    this.listBox_FileName.Items.Add(fName);
                }
            }        private void btn_Remove_Click(object sender, EventArgs e)
            {
                for (int i = this.listBox_FileName.Items.Count - 1; i >= 0; i--)
                {
                    if (this.listBox_FileName.SelectedIndices.Contains(i))
                    {
                        this.listBox_FileName.Items.RemoveAt(i);
                    }
                }
            }