當前位置:首頁 » 文件管理 » ftp目錄文件遍歷

ftp目錄文件遍歷

發布時間: 2023-01-13 07:57:35

java寫的ftp程序~~怎麼遍歷文件

//這是一個計算指定目錄所包含文件的總大小的函數
//當然涉及了遍歷文件及文件夾
void getLength(File file)
{
if(file.isDirectory())
{
File fileArray[]=file.listFiles();
for(int i=0;i<fileArray.length;i++){
getLength(fileArray[i]); //System.out.println(fileArray[i].getPath());
}
}
else if(file.isFile()){
try
{
RandomAccessFile raf=new RandomAccessFile(file,"r");
fileLength=fileLength+raf.length();
raf.close();
}catch(IOException ioe){ioe.printStackTrace();}
}
}

⑵ winform怎麼遍歷ftp上指定目錄下的所有文件

我在之前做過一個FTP的客戶端工具。 drw 文件夾 -rw 文件(有擴展名或無擴展名) 我是根據服務端返回的報文進行分析獲取的列表。 給你一些代碼片段: /// /// 獲取指定目錄下的文件和文件夾。 /// /// 要獲取的目錄 /// 要發送到FTP伺服器的密令

⑶ asp.net遍歷FTP中的文件,並進行有條件地篩選,能夠顯示文件的創建修改時間~~~求高手指教,急~~~~~~~~~

public void getDirectoryList()
{
//實例化目錄信息類 //1.獲得FTP 文件夾物理路徑
DirectoryInfo dir = new DirectoryInfo(@"E:\練習\RegeditKey\RegeditKey\");
//遍歷目錄中文件 //2.根據你要顯示文件的格式條件進行賽選, GetFiles 多後綴篩選用逗號隔開
foreach (var item in dir.GetFiles("*.txt,*.dbf,*.jpg"))
{
//遍歷 文件名,創建時間,修改時間等信息。
this.textBox1.Text+= "文件名:"+item.Name+" 創建時間"+item.CreationTimeUtc+"修改時間"+item.LastWriteTimeUtc+"\r\n";
}
}

⑷ java遍歷ftp文件夾時,在FTPFile ff[] = ftpClient.listFiles()處一直提示空指針異常錯誤,是怎麼回事。

boolean success = false; 
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(url, port);
//如果採用默認埠,可以使用ftp.connect(url)的方式直接連接FTP伺服器
ftp.login(username, password);//登錄
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);//轉移到FTP伺服器目錄
FTPFile[] fs = ftp.listFiles();

⑸ C#如何實現FTP在伺服器上遍歷文件夾

.../Image這個主文件夾是一定的,然後摟住是想在這個文件夾下創建文件夾
事先,你已經知道你所要創建的文件夾的名稱,可以這么做
if (!(Directory.Exists(path+文件名))//用這個方法判斷是否有這個文件夾。比你去遍歷文件夾要效率的多
Directory.CreateDirectory(path+文件名);//不存在則創建

⑹ 怎麼樣遍歷ftp文件夾,您的這種寫法好像不行,連接不到網路

寫不寫都行,寫得話就直接進入該目錄。用ie話在地址里打ftp://用戶名:密碼@網址:埠一般下ftp用軟體最好了,推薦你用flashfxp

⑺ 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]);
}
}

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

linux下用c語言編程遍歷遠程ftp(linux系統)指定目錄下的文件

FindFile FindNextFile

⑼ c# 如何遍歷ftp文件夾下的文件

ftp文件是一樣的
只不過路徑的格式不一樣而已

這個文件太長了 給我信箱給你發過去吧
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Sockets;

namespace zhangyuk.net.csdn.blog.ftpclient
{
/// <summary>
/// FTP Client
/// </summary>
public class FTPClient
{
#region 構造函數
/// <summary>
/// 預設構造函數
/// </summary>
public FTPClient()
{
strRemoteHost = " ";
strRemotePath = " ";
strRemoteUser = " ";
strRemotePass = " ";
strRemotePort = 21;
bConnected = false;
}

/// <summary>
/// 構造函數
/// </summary>
/// <param name= "remoteHost "> </param>
/// <param name= "remotePath "> </param>
/// <param name= "remoteUser "> </param>
/// <param name= "remotePass "> </param>
/// <param name= "remotePort "> </param>
public FTPClient( string remoteHost, string remotePath, string remoteUser, string remotePass, int remotePort )
{
strRemoteHost = remoteHost;
strRemotePath = remotePath;
strRemoteUser = remoteUser;
strRemotePass = remotePass;
strRemotePort = remotePort;
Connect();
}
#endregion

#region 登陸
/// <summary>
/// FTP伺服器IP地址
/// </summary>
private string strRemoteHost;
public string RemoteHost
{
get
{
return strRemoteHost;
}
set
{
strRemoteHost = value;
}
}
/// <summary>
/// FTP伺服器埠
/// </summary>
private int strRemotePort;
public int RemotePort
{
get
{
return strRemotePort;
}
set
{
strRemotePort = value;
}
}
/// <summary>
/// 當前伺服器目錄
/// </summary>
private string strRemotePath;
public string RemotePath
{
get
{
return strRemotePath;
}
set
{
strRemotePath = value;
}
}
/// <summary>
/// 登錄用戶賬號
/// </summary>
private string strRemoteUser;
public string RemoteUser
{
set
{
strRemoteUser = value;
}
}
/// <summary>
/// 用戶登錄密碼
/// </summary>
private string strRemotePass;
public string RemotePass
{
set
{
strRemotePass = value;
}
}

/// <summary>
/// 是否登錄
/// </summary>
private Boolean bConnected;
public bool Connected
{
get
{
return bConnected;
}
}
#endregion

⑽ 怎麼遍歷ftp伺服器裡面某個文件夾下的文件

packagecom.hmilyld.exp;importjava.io.File;publicclassListFile{privatelong[]count=newlong[]{0,0};privateFilefile;privatelong[]listFile(Stringpath){file=newFile(path);File[]f=file.listFiles();for(inti=0;i

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:713
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:980
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:687
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:840
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:747
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1086
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:314
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:194
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:883
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:841