问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Net;usingSystem.IO;namespace控制台输出{classGetFileInfo{publicstaticstringfanhui;publicstring[]ftp(stringhost,stringuser,stringpwd,stringtype){FtpWebRequestwebreq=null;FtpWebResponsewebres=null;StreamReaderstrreader=null;webreq=(FtpWebRequest)WebRequest.Create(host);webreq.Credentials=newNetworkCredential(user,pwd);webreq.Method=type;webres=(FtpWebResponse)webreq.GetResponse();Streamstream=webres.GetResponseStream();strreader=newStreamReader(stream,System.Text.Encoding.Default);stringline;StringBuilderstr=newStringBuilder();if(strreader!=null){line=strreader.ReadLine();while(line!=null){str.Append(line);str.Append("n");line=strreader.ReadLine();}}string[]fen=str.ToString().Split('n');stream.Close();strreader.Close();webres.Close();returnfen;}publicstringdownftp(stringhost,stringuser,stringpwd){string[]fullname=ftp(host,user,pwd,WebRequestMethods.Ftp.ListDirectoryDetails);string[]onlyname=ftp(host,user,pwd,WebRequestMethods.Ftp.ListDirectory);foreach(stringnamesinfullname){if(names.Contains("dr")){stringolname=names.Split('')[names.Split('').Length-1];//如果names里面包含有dr的话,host就变成了host+name就相当于找到了B文件夹varnewpath=host+"/"+olname;downftp(newpath,user,pwd);}elseif(names==""){break;}else{stringoldfilename=names.Split('')[names.Split('').Length-1];stringnewfilename=host+"/"+names.Split('')[names.Split('').Length-1];stringnewnames=names.Replace(oldfilename,newfilename);fanhui+=newnames+"n";//fanhui+=host+"/"+names.Split('')[names.Split('').Length-1]+"n";}}returnfanhui;}}classProgram{staticvoidMain(string[]args){GetFileInfofile=newGetFileInfo();strings=file.downftp("ftp://172.17.157.127","hello","123456");Console.WriteLine(s);Console.ReadKey();}}}运行出现了550问题,怎么解决啊