积极答复者
FTP下载的地址解析错误

问题
-
在写ftp下载时,遇到了这样一个问题,如果地址如下格式就不能下载,
ftp://192.168.1.2/.../../bcsy/prog/FB0100OO.BSY 。返回的是550。用的是FtpWebRequest和FtpWebResponse。该如何解决?
答案
全部回复
-
string fileurl = "ftp://192.168.1.3/../../bcsy/prog/FB0100OO.BSY";
MessageBox.Show(fileurl);
try
{
ftpWBR = (FtpWebRequest)WebRequest.Create(new Uri(fileurl));
ftpWBR.Credentials = new NetworkCredential("abc", "abc");ftpWBR.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
ftpWBR.UseBinary = true;
FtpWebResponse listResponse = (FtpWebResponse)ftpWBR.GetResponse();
MessageBox.Show(listResponse.WelcomeMessage);}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
FtpWPS = (FtpWebResponse)ftpWBR.GetResponse();
MessageBox.Show(FtpWPS.WelcomeMessage);
instream = FtpWPS.GetResponseStream();
if (instream == null)
{
MessageBox.Show("查无此文件!");
}
else
{
MessageBox.Show("找到文件正在下载!");
Byte[] bytearray = new Byte[4096];
outstream = File.OpenWrite(@"D:\FB0100OO.BSY");
int tempflag = 0;
while ((tempflag = instream.Read(bytearray, 0, 4096)) > 0)
{
outstream.Write(bytearray, 0, tempflag);
}
MessageBox.Show("下载完成!");
} -