FTP上传时遇到的BUG?

Somnus_YOYO 2010-05-24 02:16:04
我用FTP类上传文件时只有文件名含有#号它就自动把#号和#号后的文件全删除了 是怎么回事呢
...全文
115 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
anbin0814 2010-05-24
  • 打赏
  • 举报
回复
接分。。。
mars199 2010-05-24
  • 打赏
  • 举报
回复
不懂帮顶
Somnus_YOYO 2010-05-24
  • 打赏
  • 举报
回复
弄错了不是文件全删了 是把#号和#号的文件名字全删了
Somnus_YOYO 2010-05-24
  • 打赏
  • 举报
回复
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);
}
}
}
捷哥1999 2010-05-24
  • 打赏
  • 举报
回复
你把上传的代码贴出来看看,#并不是ftp的一个命令,ftp的全部命令在这里:
http://www.edu.cn/20010830/210045.shtml

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧