drw 文件夹
-rw文件(有扩展名或无扩展名)
我是根据服务端返回的报文进行分析获取的列表。
给你一些代码片段:
/// <summary>
/// 获取指定目录下的文件和文件夹。
/// </summary>
/// <param name="path">要获取的目录</param>
/// <param name="WRMethods">要发送到FTP服务器的胡森密令。</param>
/// <returns></returns>
public string[] GetFileList(string path, string WRMethods)//从ftp服务器上获得文件列表
{
WebResponse response
string[] downloadFiles
int conut = 4
StringBuilder result = new StringBuilder()
Connect(path)
if (FTPVariable.IsUseProxy_ftp)
{
reqFTP.Proxy = FtpProxy.GetFtpSelectProxy(FTPVariable.FtpCommand_transferProxyName)
}
reqFTP.ReadWriteTimeout = 12000
//如果不应销毁到服务器的连裤拿亩接,则为 true;否则为 false。默认值为 true。
//
reqFTP.Method = WRMethods
try
{
response = (FtpWebResponse)reqFTP.GetResponse()
goto Ftp_lbl_03
}
catch (WebException webex)
{
GetReply(webex.Message)
if (ReplyCode == 530)// 未登录敏好。
{
goto Ftp_lbl_04
}
else if (ReplyCode == 550)
{
goto Ftp_lbl_04
}
else
{
FtpManage.SetLog("获取列表超时,等候1秒后重试!")
goto Ftp_lbl_01
}
}
Ftp_lbl_01:
try
{
FtpManage.SetLog("正在连接服务器 " + FtpRemoteHost)
response = GetRequest(path, WRMethods)
}
catch (WebException)
{
FtpManage.SetLog("获取列表超时,等候1秒后重试!")
downloadFiles = null
System.Threading.Thread.Sleep(1000)
if (conut == 0)
{
goto Ftp_lbl_02
}
conut--
goto Ftp_lbl_01
}
catch (Exception ex)
{
MSG.Show(ex.Message, Global.GetRS["msgTilteError"], MessageBoxButton.OK, MsgIco.Error)
FtpManage.SetLog("命令执行失败,原因:" + ex.Message)
downloadFiles = null
return downloadFiles
}
Ftp_lbl_03:
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default)//中文文件名
string line = reader.ReadLine()
while (line != null)
{
result.Append(line)
result.Append("\n")
line = reader.ReadLine()
}
if (result.Length == 0)
{
return null
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1)
reader.Close()
response.Close()
FtpManage.SetLog("命令已成功执行")
return result.ToString().Split('\n')
Ftp_lbl_04:
FtpManage.SetLog(ReplyInfo)
return null
Ftp_lbl_02:
FtpManage.SetLog("550 获取列表失败,无法连接远程服务器!")
FtpManage.ftpmanage.IsRefurbish = true
return null
}
/// <summary>
/// 获取指定目录下的文件和文件夹。
/// </summary>
/// <param name="path">要获取的目录</param>
/// <returns></returns>
public string[] GetFileList(string path)//从ftp服务器上获得文件列表
{
return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectory)
}
/// <summary>
/// 获取指定目录下的文件和文件夹。
/// </summary>
/// <returns></returns>
public string[] GetFileList()//从ftp服务器上获得文件列表
{
return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/", WebRequestMethods.Ftp.ListDirectory)
}
/// <summary>
/// 获取目录和文件名,返回目录表。
/// </summary>
/// <param name="path">要获取的目录</param>
/// <returns></returns>
public string[] GetCatalog_FileList(string path)
{
string[] fountainhead = GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectoryDetails)
string[] Catalog = null
if (fountainhead == null)
{
return null
}
Catalog = new string[fountainhead.Length]
for (int i = 3i <fountainhead.Lengthi++)
{
Catalog[i - 3] += fountainhead[i].Substring(55, fountainhead[i].Length - 55) + "&"//FileName
Catalog[i - 3] += fountainhead[i].Substring(30, 12) + "&"//FileSize
Catalog[i - 3] += fountainhead[i].Substring(42, 13) + "&"//AmendDate
Catalog[i - 3] += fountainhead[i].Substring(0, 3) + "&"
}
return Catalog
}
/*** 取得相对于咐团当前连接目录的某个目燃哪录下所有文件列表
*
* @param path
* @return
*/
public List getFileList(String path){
List list = new ArrayList()
DataInputStream dis
try {
dis = new DataInputStream(ftpClient.nameList(this.path + path))
String filename = ""
while((filename = dis.readLine()) != null){
list.add(filename)
}
} catch (IOException e) {
e.printStackTrace()
}
return list
}
我从这里拷来的 你不清楚看看里面 http://hi.baidu.com/yuanhotel/item/000b6334894d11f42784f4da
满意皮简码就采纳 谢谢
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)