當前位置:首頁 » 文件傳輸 » ftp下載目錄下所有文件名
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

ftp下載目錄下所有文件名

發布時間: 2022-05-20 04:36:20

Ⅰ 怎麼獲得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;
}