源码: string ftpServerIP = System.Configuration.ConfigurationManager.AppSettings["serverIP"].ToString();
string ftpUserID = System.Configuration.ConfigurationManager.AppSettings["ftpUserName"].ToString();
string ftpPassWord = System.Configuration.ConfigurationManager.AppSettings["ftpPassWord"].ToString();
Stream stream = null;
StreamReader reader = null;
try
{
//根据URL创建FtpWebRequest对象
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + ftpServerIP + filePath));
//通信凭证(用户名、密码方式)
ftpRequest.Credentials = new NetworkCredential(ftpUserID, ftpPassWord); ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
//返回 FTP 服务器响应。
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
stream = ftpResponse.GetResponseStream();
long cl = ftpResponse.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = stream.Read(buffer, 0, bufferSize);
FileStream outputStream = new FileStream(savefilePath, FileMode.Create);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = stream.Read(buffer, 0, bufferSize);
}
outputStream.Close();
if (i32Num == ftpFileCount)
{
Log.ITestMessageShow("Download successfully.");
}
}
catch (Exception ex)
{
switch (ex.Message.ToString())
{
case "远程服务器返回错误: (530) 未登录。":
CustomMessageBox.GetKey("FTPUploadFile", "Message");
break;
case "远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。":
CustomMessageBox.GetKey("FTPDownloadNoFile", "Message");
break;
default:
break;
}
//Log.ITestMessageShow("FTP file read failure!\r\nMay be the wrong path or file does not exist.");
Log.ICreateLog(this.GetType().ToString(), "OperateFormControlInvoke", ex.Message);
return false;
}
finally
{
if (reader != null) { reader.Close(); }
if (stream != null) { stream.Close(); }
}
return true;在连接相同的服务器端,下载相同的文件,都是XP操作系统。在本人自己的机子上是可用的,但是在别的机子上源码就不行,提示:远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。
请问是什么原因引起的?有什么办法?
string ftpUserID = System.Configuration.ConfigurationManager.AppSettings["ftpUserName"].ToString();
string ftpPassWord = System.Configuration.ConfigurationManager.AppSettings["ftpPassWord"].ToString();
Stream stream = null;
StreamReader reader = null;
try
{
//根据URL创建FtpWebRequest对象
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + ftpServerIP + filePath));
//通信凭证(用户名、密码方式)
ftpRequest.Credentials = new NetworkCredential(ftpUserID, ftpPassWord); ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
//返回 FTP 服务器响应。
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
stream = ftpResponse.GetResponseStream();
long cl = ftpResponse.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = stream.Read(buffer, 0, bufferSize);
FileStream outputStream = new FileStream(savefilePath, FileMode.Create);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = stream.Read(buffer, 0, bufferSize);
}
outputStream.Close();
if (i32Num == ftpFileCount)
{
Log.ITestMessageShow("Download successfully.");
}
}
catch (Exception ex)
{
switch (ex.Message.ToString())
{
case "远程服务器返回错误: (530) 未登录。":
CustomMessageBox.GetKey("FTPUploadFile", "Message");
break;
case "远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。":
CustomMessageBox.GetKey("FTPDownloadNoFile", "Message");
break;
default:
break;
}
//Log.ITestMessageShow("FTP file read failure!\r\nMay be the wrong path or file does not exist.");
Log.ICreateLog(this.GetType().ToString(), "OperateFormControlInvoke", ex.Message);
return false;
}
finally
{
if (reader != null) { reader.Close(); }
if (stream != null) { stream.Close(); }
}
return true;在连接相同的服务器端,下载相同的文件,都是XP操作系统。在本人自己的机子上是可用的,但是在别的机子上源码就不行,提示:远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)。
请问是什么原因引起的?有什么办法?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货