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

ftp獲取目錄下文件數量

發布時間: 2022-12-12 23:59:24

1. java如何獲取ftp制定目錄下所有文件集合(包括文件名稱)只要一個方法。

/**
* 取得相對於當前連接目錄的某個目錄下所有文件列表
*
* @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..com/yuanhotel/item/000b6334894d11f42784f4da
滿意就採納 謝謝

2. java 怎麼遍歷ftp目錄下的所有目錄以及目錄下的文件名稱,取出文件的相對路徑

package com.hmilyld.exp;

import java.io.File;

public class ListFile {

private long[] count = new long[] { 0, 0 };

private File file;

private long[] listFile(String path) {
file = new File(path);
File[] f = file.listFiles();
for (int i = 0; i < f.length; i++) {
if (f[i].isDirectory()) {
count[0]++;
this.listFile(f[i].getPath());
} else {
count[1]++;
}
}
return count;
}

/**
* 得到指定路徑下的文件和文件夾數量
*
* @param path
* 要查看的路徑
* @return object[0]耗時(毫秒)<br>
* object[1]文件夾數量<br>
* object[2]文件數量
*/
public Object[] getFileCount(String path) {
long t = System.currentTimeMillis();
long[] count = this.listFile(path);
t = System.currentTimeMillis() - t;
Object[] o = new Object[] { Long.valueOf(t), Long.valueOf(count[0]),
Long.valueOf(count[1])};
return o;
}

public static void main(String[] args) {
ListFile l = new ListFile();
Object[] count = l.getFileCount("d:\\");
System.out.println(count[0]);
System.out.println(count[1]);
System.out.println(count[2]);
}
}

以前寫的一個獲取目錄下有多少文件和多少文件夾的代碼,
可以參考下.:)

3. 在FTP命令當中查看本地文件列表命令是

查看本地文件列表命令是:ls

其它常用的FTP命令及含義:

1、dir:顯示伺服器目錄和文件列表

2、cd:進入伺服器指定的目錄(dir命令可以使用通配符「」和「?」,比如,顯示當前目錄中所有擴展名為jpg的文件,可使用命令 dir .jpg。)

3、put:上傳指定文件put filename [newname]

4、、send:上傳指定文件send filename [newname]

(filename為上傳的本地文件名,newname為上傳至FTP伺服器上時使用的名字,如果不指定newname,文件將以原名上傳。)

(3)ftp獲取目錄下文件數量擴展閱讀

ftp命令行格式及開關含義:

ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]

-v - 禁止顯示遠程伺服器相應信息

-n - 禁止自動登錄

-i - 多文件傳輸過程中關閉交互提示

-d - 啟用調試,顯示所有客戶端與伺服器端傳遞的命令

-g - 禁用文件名通配符,允許在本地文件和路徑名中使用

-s:filename - 指定包含 FTP 命令的文本文件;命令在FTP啟動後自動運行。此參數中沒有空格。可替代重定向符(>)使用。

-a - 在綁字數據連接時使用所有本地介面

-w:windowsize - 覆蓋默認的傳輸緩沖區大小 65535。

computer - 指定遠程電腦計算機名或IP地址。此參數必須放到最後。

4. windowsftp如何獲取文件夾下所有的文件

可以通過命令窗口來打開所有的文件。具體步驟如下:
點擊win+R後輸入cmd打開dos命令窗口。
打開需獲取文件名的位置。
獲取名稱,命令格式:dir/b文件目標盤符文件夾位置(可省略)目標名稱.目標後綴。
獲取文件大小及文件名、修改時間(文件大小需處理)。
Microsoft Surface是一個由微軟所開發的第一款平面電腦,結合硬體與軟體的新技術,用家可以直接用手或聲音對屏幕作出指令,觸摸和其他外在物理物來和電腦進行交互,毋須再依賴會令手部勞損的滑鼠與鍵盤。

5. FTP 怎麼查看本地的文件列表

一個簡單的問題,ftp到遠程伺服器之後需要上傳一個文件,但是我忘記了本地需要上傳的文件名,因此需要查看本地目錄。
解決方法:
一、cd到本地目錄
二、ls命令查看本地目錄的內容。

6. 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;
}

7. linux下ftp到另一台伺服器,如何查看伺服器上的某個目錄下的文件個數:

您登陸到ftp上用ls |wc -l就可以,直接列出有多少個文件目錄,我記得在57CTO技術論壇看到過。