日期:2014-05-17 浏览次数:21036 次
// 创建FTP连接
private FtpWebRequest CreateFtpWebRequest(string uri, string requestMethod)
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(uri);
request.Credentials = networkCredential;//获取或设置用于与 FTP 服务器通信的凭据。
request.KeepAlive = true;
request.UseBinary = true;
request.Method = requestMethod;
return request;
}
// 获取服务器返回的响应体
private FtpWebResponse GetFtpResponse(FtpWebRequest request)
{
FtpWebResponse response = null;
try
{
response = (FtpWebResponse)request.GetResponse();//检索包含从 FTP 服务器上发送的响应数据的流
lstbxFtpState.Items.Add("验证完毕,服务器回应信息:[" + response.WelcomeMessage + "]");
lstbxFtpState.Items.Add("正在连接:[ " + response.BannerMessage + "]");
lstbxFtpState.TopIndex = lstbxFtpState.Items.Count - 1;
return response;
}
catch(WebException ex)
{
lstbxFtpState.Items.Add("发送错误。返回信息为:" + ex.Status);
lstbxFtpState.TopIndex = lstbxFtpState.Items.Count - 1;
return null;
}
}