当前位置:首页 » 文件管理 » 遍历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服务器的密令

热点内容
数据结构对算法的影响 发布:2024-10-06 18:21:28 浏览:32
服务器托管ip不变 发布:2024-10-06 18:21:20 浏览:421
网盘加密软件 发布:2024-10-06 18:16:17 浏览:123
儿童配置保险怎么买 发布:2024-10-06 18:07:32 浏览:733
ipad存储器 发布:2024-10-06 18:00:07 浏览:534
c语言void返回值 发布:2024-10-06 18:00:02 浏览:319
bat执行shell脚本 发布:2024-10-06 17:59:24 浏览:330
sql单引号双引号 发布:2024-10-06 17:41:51 浏览:572
macbookpro选哪个配置 发布:2024-10-06 16:50:01 浏览:141
linux基础命令 发布:2024-10-06 16:37:59 浏览:411