- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Apache Commons Net 3.2,我的程序连接到 FTP 服务器并从中下载文件。
但是,它应该能够做的是读取服务器上的文件而不下载它们。
这可能吗?
只是服务器包含大量个人信息,SSN、电话、电子邮件等,只有拥有正确密码的特定人员才能访问它们。
任何人都不能从服务器下载任何内容,至少在没有我的程序授予的最高级别权限的情况下!
到目前为止,我有一个 FTPFile [],其中包含服务器上的所有数据文件。
我想循环遍历它们,看看它们上是否有当前用户的名字(意味着他们被允许查看这个人/文件),如果有,则将它们的数据添加到 ArrayList 中。
有什么建议吗?
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Arrays;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class Server {
private static final String server = "/server";
private static final String host = "00.000.0.0";
private static final String user = "username";
private static final String pass = "password";
private static List <FTPFile> data;
private static FTPClient ftp = new FTPClient ();
public static void load (String folder) {
try {
// Connect to the SERVER
ftp.connect(host, 21);
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
System.out.println("Could not connect to the server.");
return;
}
// Login to the SERVER
ftp.enterLocalPassiveMode();
if (!ftp.login(user, pass)) {
System.out.println("Could not login to the server.");
return;
}
// Get DATA from the SERVER
System.out.println(server + "/" + folder);
data = Arrays.asList(ftp.listFiles(server + "/" + folder));
System.out.println(data.size());
for (int f = 0; f < data.size(); f++)
System.out.println(data.get(f).getName());
// Disconnect from the SERVER
ftp.logout();
ftp.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String read (FTPFile file) {
try {
String name = file.getName();
File tempFolder = new File ("temp/" + name);
tempFolder.mkdirs();
// Create a TEMPORARY DATA FILE
File tempFile = new File (tempFolder.getAbsolutePath() + "/data");
System.out.println(tempFile.getAbsolutePath());
tempFile.createNewFile();
tempFile.deleteOnExit();
// Get ready to DOWNLOAD DATA from the SERVER
FileOutputStream out = new FileOutputStream (new File (name));
ftp.connect(host, 21);
ftp.login(user, pass);
// DOWNLOAD and DISCONNECT
ftp.retrieveFile(name, out);
out.close();
ftp.logout();
ftp.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return ""; // This should return a String with data read from the file
}
}
最佳答案
如果您想“读取”(如检查其内容)一个文件,您必须下载该文件,即将其内容从服务器传输到客户端。当您仅限于客户端解决方案时,就没有办法解决这个问题。
一般来说,仅在客户端检查用户权限不是一个好主意。如果恶意用户拥有访问服务器的正确凭据(可以从客户端提取),他就可以绕过客户端授权,使其变得毫无用处。
用户的身份验证和授权应始终在服务器端进行。
在您的示例中,您可以考虑在 ftp 服务器上创建不同的用户以及访问、读取和写入文件/目录的适当权限。
关于Java + Apache Commons Net : Read FTPFile Without Downloading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14487075/
我有一个阅读器,其中包含有关 51*51 网格的信息,其中网格上的每个点都由 f32 表示。 .我想将这些数据读入一个向量,以便我可以轻松处理它: pub fn from_reader(reader:
我重新启动了 SQL Server 2005 并运行了统计 IO 的查询。 我得到了这些结果:表“xxx”。扫描计数 1,逻辑读取 789,物理读取 3,预读读取 794,... 预读读取数是读取并放
在 CLHS 中,我为 :read-only x 读到:“当 x 为真时,这指定不能更改此插槽;它将始终包含构造时提供的值。” 我可以做到这一点(CCL、SBCL): CL-USER> (defstr
让我们考虑一下这句话(Total Store Ordering): reads are ordered before reads, writes before writes, and reads be
我正在开发一个 SMTP 库,它使用缓冲读取器通过网络读取行。 我想要一种安全的方式来从网络读取数据,而不依赖于 Rust 内部机制来确保代码按预期工作。具体来说,我想知道 Read trait 是否
我不清楚所有这些读取字符串函数之间的关系。嗯,很明显clojure.core/read-string可以读取 pr[n] 输出的任何序列化字符串甚至 print-dup .也很清楚clojure.ed
所以我做了这个功能,就像倒计时一样。我想在倒计时减少时读取命令。我的大问题是让 read() 在倒计时减少时等待输入。如您所见,我尝试使用 select() 但在第一个 printf 之后("time
这是我vue3+echart5 遇到的报错:Cannot read properties of undefined (reading ‘type‘) 这个问题需要搞清楚两个关键方法: toRaw: 作
下图中,左边是C代码,右边是未优化的LLVM IR形式。 The Figure 在 IR 上运行 MemoryDependenceAnalysis 可查找内存依赖性。原始代码及其 IR 等效代码中
这个问题在这里已经有了答案: Read values into a shell variable from a pipe (17 个答案) 关闭 3 年前。 我一直在尝试像这样从程序输出中读取环境变
当我输入相同的整数时,如何将整数转换为与使用 read(0,buff,nbytes) 获得的缓冲区相同的值/编码字符?我正在尝试编写类似 read() 的东西,但用整数数据代替读取到缓冲区的文件描述符
This question already has answers here: Closed 2 years ago. Read input in bash inside a while loop (
我正在尝试处理来自 MySQL 数据库的一些数据(主要是 double 值)。我收到此错误消息: Invalid attempt to access a field before calling Re
我正在制作一个简单的 TCP/IP 套接字应用 这样做有什么不同: DataInputStream in = new DataInputStream(clientSocket.getInputStre
我操作API服务器。 手机APP访问API服务器时,有时会出现该异常。 我尝试在测试服务器上进行测试,但无法重现。(我改变了apache和tomcat的连接时间。) 有什么问题?? 我该如何解决这个问
我在段落末尾使用“阅读更多”只是为了提醒像P.T.O一样的用户 为什么会有问题? 最佳答案 您必须明白,许多屏幕阅读器用户不会等到整个页面都读给他们听。他们使用键盘快捷键在页面中导航。 JAWS(可以
我已将我的 Angular 应用程序从 12 版本升级到 13 版本。我在单元测试运行期间开始遇到此错误。 Chrome Headless 94.0.4606.61 (Windows 10) AppC
我正在尝试为以下组件编写一个。我正在使用 queryParams 然后使用 switchmap 来调用服务。这是 url 的样子: http://localhost:4200/test-fee/det
我的代码有什么问题? Uncaught TypeError: Cannot read properties of undefined (reading 'remove') 和 Uncaught Typ
我在我的 React 应用程序中遇到了这个问题。 类型错误:无法读取未定义的属性(读取“requestContent”) 我在我的应用程序中使用 commercejs。代码指向 isEmpty=!ca
我是一名优秀的程序员,十分优秀!