110,499
社区成员
发帖
与我相关
我的任务
分享
private bool FtpUpFile(string strFileName, string strFtpUrl)
{
string strFtpUser = "admin";
string strFtpPassword = textBox3.Text;
FileInfo fileInf = new FileInfo(strFileName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
//int allbye = (int)fileInf.Length;
//int startbye = 0;
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
//startbye += contentLen;
}
richTextBox1.AppendText(strFileName.Remove(0,strFileName.LastIndexOf(@"\")+1) + " --已上传\n");
richTextBox1.ScrollToCaret();
strm.Close();
fs.Close();
return true
}