using System.Net;
static private string path = @"ftp://" + "10.55.11.11" + "/"; //目标路径10.55.2.48
static private string ftpip = "10.55.11.11"; //ftp IP地址
static private string username = "temp"; //ftp用户名
static private string password = "temp";
public void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = path +fileInf.Name;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(username, password);
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();
}
catch (Exception ex)
{
throw new Exception("Ftphelper Upload Error --> " + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
//Download("1233.docx");
//Download("D8Ecap.zip");
//Download("Weekly_Report2.xlsx");
Upload(@"E:\\ftpDownload\Mysql.pptx");
}