写了一个小工作用C# 通过FtpWebRequest 下载服务器文件。
本机运行OK,部署到客户机器上运行程序就报“无法连接到远程服务器”,但客户的IE是可以打开这个FTP地址的。
错误信息是程序跑到WebResponse response = reqFTP.GetResponse()抛出的。
急!!!请帮忙!
你的请求链接代码能不能贴出来看一下,超时之类的设置一下。
public string[] GetFileList(string ftppath)
{
string[] ftpPath = { "" };
string ftpUser = frmC.txtFtpUsr.Text.Trim();
//MessageBox.Show(ftpPath);
string ftpPwd = frmC.txtFtpPassword.Text.Trim();
//ftpUser = "";
//ftpPwd = "";
//MessageBox.Show(ftpUser);
//MessageBox.Show(ftpPwd);
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftppath));
reqFTP.UseBinary = true; reqFTP.UsePassive = false;
System.Net.WebClient mm = new System.Net.WebClient();
//reqFTP.UseDefaultCredentials = true;
reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
if (line == null)
{
MessageBox.Show("服务器文件不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return ftpPath;
}
while (line != null)
{
result.Append(line); result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
ftpPath = result.ToString().Split('\n');
return ftpPath;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return ftpPath;
}
}
这一段是先遍历目录下的所有文件。跑到WebResponse response = reqFTP.GetResponse()错误就抛出“无法连接到远程服务器”
会不会是因为数据库连接问题导致的