Ⅰ 怎么获得FTP服务器上目录下的所有文件名和子目录
不要使用tidftp,长时间搜索会出现死锁现象,使用WinInet单元
procere TFtpScan.Execute;
var
FFTPHandle: HINTERNET;
FInetHandle: HINTERNET;
Enum: HINTERNET;
FFindFileData: WIN32_FIND_DATA;
R: Boolean;
FFileName, DataStr: string;
TempErrorCode: Cardinal;
begin
Ⅱ java怎样获取ftp目录下的所有子文件名
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建File对象
File file = new File("d:\\");
// 使用递归方法做
dg(file);
}
private static void dg(File fl) {
// TODO Auto-generated method stub
// 创建file数组用来存储数据
File[] filArr = fl.listFiles();
// 判断FiLe数组不能为空
if (filArr != null) {
// 使用for遍历
for (File f : filArr) {
// 如果是文件夹 就递归
if (f.isDirectory()) {
// 递归
dg(f);
} else if (f.isFile()) {
System.out.println(f.getAbsolutePath());
}
}
}
}
Ⅲ win7搭建ftp服务器,下载时文件名乱码
ftp服务目录下的文件出现乱码,多数是因为中文编码不统一导致的,多见于第三方的ftp服务软件,比如server-u,另外跨平台访问也会出现这种情况,比如通过Linux访问windows上的ftp服务器。解决的方法可以参考如下解决方法。
1、ftp服务目录下的文件,统一使用英文名称 ,不要使用中文名称。
2、设置好编码,以server-u为例说明:
1)、打开Serv-U控制台,点击“限制和设置”--“为域配置高级FTP命令设置和行为”。
2)、在FTP设置中找到OPTS UTF8命令,右击禁用此命令。
3)、点击下面的“全局属性”。
4)、在出来的FTP命令属性选项卡中,“高级选项”里,把“对所有收发的路径和文件名使用UFT-8编码”前面的钩去掉。
Ⅳ 用bat批处理命令获取ftp服务器目录下的文件名及子目录下的文件名...各位大神帮帮忙
@echooff
seth=192.168.1.100
setu=ftpuser
setp=12345678
echoopen%h%>ftp.txt
echo%u%>>ftp.txt
echo%p%>>ftp.txt
echodir>>ftp.txt
echobye>>ftp.txt
ftp-s:ftp.txt>ftpdir.txt
echoopen%h%>ftp.txt
echo%u%>>ftp.txt
echo%p%>>ftp.txt
for/f"tokens=4"%%iin('findstr"<DIR>"ftpdir.txt')do(
echocd%%~i>>ftp.txt
echodir>>ftp.txt
echocd..>>ftp.txt)
echobye>>ftp.txt
ftp-s:ftp.txt>ftpfile.txt
notepadftpfile.txt
Ⅳ linux下如何用FTP下载含有特定文件名的文件
如果命令行下载只能一个一个下,用客户端直接多个一起下;或者干脆用sftp下载就可以record* 全部下载了
Ⅵ C#如何取得ftp上面的所有文件夹里面的所有文件名,求源码。。。。
连接方法:
string ftpServerIP = "";
string ftpUserID = "";
string ftpPassword = "";
string TempPath = Path.GetTempPath();
FtpWebRequest reqFTP;
DataTable dt;
private void Connect(String path)//连接ftp
{
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
}
catch (Exception){
Response.Write("<srcipt>alert('连接失败!')</script>");
}
获取方法:
private string[] GetFileList(string path, string WRMethods)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
try
{
Connect(path);
reqFTP.Method = WRMethods;
WebResponse response = reqFTP.GetResponse();
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();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString().Split('\n');
}
catch (Exception)
{
downloadFiles = null;
return downloadFiles;
}
}
调用:
string[] str = GetFileList("ftp://" + ftpServerIP + "/" + path, WebRequestMethods.Ftp.ListDirectoryDetails);
数组就是ftp文件夹下的所有文件名,如果要判断ftp根下面的是文件还是文件夹。需要解字符串才行!
Ⅶ C# 获取Ftp某个目录下的所有文件(不要文件夹)
我在之前做过一个FTP的客户端工具。
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 = 3; i < fountainhead.Length; i++)
{
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;
}