赞
踩
- private void Ftp(string file_name)
- {
-
- FileInfo fi = new FileInfo("D:\\\\" + file_name + ".csv");
- //定义上传目录
- string url = "ftp://transfer.ymtc.com/Data_Transfer/" + file_name + ".csv";
-
- FtpWebRequest ftp;
- ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
- //ftp账号密码
- ftp.Credentials = new NetworkCredential("账号", "密码");
- //公司都是代理上网,所以如果不加这句话,就会报错误【使用 HTTP 代理时不支持请求的 FTP 命令。】
- ftp.Proxy = null;
- ftp.KeepAlive = false;
- ftp.Method = WebRequestMethods.Ftp.UploadFile;
- ftp.UseBinary = true;
- ftp.ContentLength = fi.Length;
-
- int buffLength = 2048;
- byte[] be = new byte[buffLength];
- int contentLen;
- using (FileStream fs = fi.OpenRead())
- {
- using (Stream s = ftp.GetRequestStream())
- {
- contentLen = fs.Read(be, 0, buffLength);
- while (contentLen != 0)
- {
- s.Write(be, 0, contentLen);
- contentLen = fs.Read(be, 0, buffLength);
- }
- s.Close();
- }
- fs.Close();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。