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

遍歷ftp

發布時間: 2022-11-04 20:52:10

❶ 怎麼遍歷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

❷ 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();

❹ 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();}
}
}

❺ 如何遍歷列出ftp下目錄及子目錄

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

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

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

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

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

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

❽ 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遍歷目錄的問題

你這個ftp是用的都是同一個對象,每次遞歸workfolder都被update掉了。。。。當然會不繼續遍歷,改成每次都Generate一個New的ftp吧。
補充:
本來你ftp指向目錄A,後來進入遞歸被改成指向A/B了,你說遍歷還能准確嗎?
還有個方法就是每次遞歸回來調用:
ftp.changeWorkingDirectory(ftpPath);
把Path給設置回來。不過不確定這個方法穩定,可以先Try一下。
public void listFilesDir(String path) throws IOException{
String ftpPath = path;
ftp.changeWorkingDirectory(ftpPath);
FTPFile[] files = ftp.listFiles();
for(FTPFile ff:files){
if(!ff.isDirectory()){
System.out.println("文件:" + ff.getName());
}
else{
if(!ff.getName().startsWith(".")){
ftpPath = ff.getName() + "/";
System.out.println("目錄 " + ff.getName() + " 下的文件文件或目錄:");
ftp.changeWorkingDirectory(ftpPath);
listFilesDir(ftpPath);
ftp.changeWorkingDirectory(path);
}
}
}
}
再補充:
中文的話試試看用GBK。。。Java項目的編碼記得也要一樣的。

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

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

熱點內容
交換機ip地址為什麼要配置 發布:2024-10-06 20:31:56 瀏覽:375
qq瀏覽器如何取消保存密碼 發布:2024-10-06 20:14:48 瀏覽:649
shell腳本ctrlc 發布:2024-10-06 20:10:37 瀏覽:888
壓縮板好嘛 發布:2024-10-06 20:10:28 瀏覽:670
java編譯基礎教程 發布:2024-10-06 20:09:47 瀏覽:268
我的世界電腦java怎麼玩伺服器 發布:2024-10-06 19:16:54 瀏覽:480
存儲空間大於存儲池中的可用容量 發布:2024-10-06 19:15:28 瀏覽:33
什麼叫估演算法 發布:2024-10-06 19:15:20 瀏覽:87
c語言庫編譯 發布:2024-10-06 19:09:23 瀏覽:747
啊里雲系統電視如何更換安卓系統 發布:2024-10-06 18:50:09 瀏覽:577