FTP上传的代码
FileInfo fileInf = new FileInfo(System.Environment.UserName + ".txt");
string Url = ftp的URL+文件名
FtpWebRequest reqFtp;
reqFtp = (FtpWebRequest)FtpWebRequest.Create(new Uri(Url));
reqFtp.Credentials = new NetworkCredential(ftp的用户名,ftp密码);
reqFtp.KeepAlive = false;
reqFtp.Method=WebRequestMethods.Ftp.UploadFile;
reqFtp.UseBinary = true;
reqFtp.UsePassive = false;
reqFtp.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs=fileInf.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();
//fileInf.Delete();
}
string Url = ftp的URL+文件名
FtpWebRequest reqFtp;
reqFtp = (FtpWebRequest)FtpWebRequest.Create(new Uri(Url));
reqFtp.Credentials = new NetworkCredential(ftp的用户名,ftp密码);
reqFtp.KeepAlive = false;
reqFtp.Method=WebRequestMethods.Ftp.UploadFile;
reqFtp.UseBinary = true;
reqFtp.UsePassive = false;
reqFtp.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs=fileInf.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();
//fileInf.Delete();
}