标签: apache-commons-net

使用commons-net连接到FTPS服务器时,"534策略需要SSL"

我正在尝试使用commons-net库连接到FTPS服务器.我可以正常连接但是当我尝试列出文件时,我收到错误"534 Policy required SSL".

import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.commons.net.util.TrustManagerUtils;

public class Test {

    public static void main(String[] args) throws SocketException, IOException {
        FTPSClient c = new FTPSClient("SSL", false);
        c.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
        c.connect("10.10.6.225", 21);
        c.login("ftpuser", "Passw0rd");
        c.changeToParentDirectory();
        for (String s : c.getReplyStrings()) {
            System.out.println(s);
        }

        c.listFiles();
        for (String s : c.getReplyStrings()) {
            System.out.println(s);
        }
        for (FTPFile f : c.listFiles("/TestFolder")) {
            System.out.println("file");
            System.out.println(f.getName());
        }
        c.disconnect();
    }

}
Run Code Online (Sandbox Code Playgroud)

java ftps apache-commons-net

2
推荐指数
1
解决办法
5334
查看次数

Apache Commons net中的execProt("P")是什么?

我在我的aws ec2实例上设置了一个FTPS服务器.我正在使用Apache Commons net以编程方式连接到我的服务器.

try
{
    ftps.enterLocalPassiveMode();
    ftps.setBufferSize(1000);
    ftps.execPROT("P");

    if (!ftps.login(username, password))
    {
        ftps.logout();
        error = true;
        break __main;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我没有设置execProt("P"),我无法检索文件.从他们的文档中,我看到"P"代表私有数据通道保护级别.这是什么意思?为什么我使用P而不是"S"或"E"?

java ssl ftps apache-commons-net

2
推荐指数
1
解决办法
2033
查看次数

如何使用 apache commons net ftp 更改 ftp 服务器上文件的权限?

如果有来自服务器的 ftp 文件列表,我该如何更改其中一个文件的权限?

如果有人可以为我指出教程或向我展示示例,我将不胜感激。我已经弄清楚如何更改文件中的权限,但不知道如何在服务器上永久更改。

有什么建议?

java apache-commons-net

1
推荐指数
1
解决办法
5609
查看次数

如何使用Scala中的apache commons(或不属于jdk的任何其他库)

看起来这应该很简单,但我不是一个java家伙.我打算尝试使用apache commons ftp组件(org.apache.commons.net.ftp),但我不知道如何使我的scala代码可以访问它.

目前,我刚刚尝试将软件包放入目录,从该目录启动scala repl,并发出:import org.apache.commons.*我被告知apache不是package org的成员,我假设它意味着找不到代码.

这看起来应该很容易,但任何建议都会受到赞赏.

scala apache-commons-net

1
推荐指数
2
解决办法
1319
查看次数

奇怪的FTPClient.storeFile行为

我在将文件上传到FTP服务器时遇到了一些问题.

我写了这段代码,应该连接到FTP服务器,登录,并使用Apache Commons Net FTPClient上传文件:

FTPClient client = new FTPClient();
client.connect("somesite.com");
client.login("user", "password");
System.out.println("connected");

client.cwd("images/bar");
System.out.println("cwd succesful. Full reply: "+client.getReplyString());

FileInputStream fis = new FileInputStream(new File(System.getProperty("user.dir")+File.separator+"current_690.jpg"));
client.storeFile(image_name, fis);
System.out.println("Succesful store. Full reply: "+client.getReplyString());
Run Code Online (Sandbox Code Playgroud)

终端的输出是:

connected
cwd succesful. Full reply: 250 OK. Current directory is /images/bar

Succesful store. Full reply: 226-File successfully transferred
226 3.190 seconds (measured here), 9.99 Kbytes per second
Run Code Online (Sandbox Code Playgroud)

问题是,如果我去我的user.dir并打开current_690.jpg它会正确显示我的图像,但如果我下载我刚刚上传的FTPClient图像,当我打开它时,操作系统说Unable to preview the image, probabily it's corrupted or it's too big.

事实上我注意到在我的电脑上我的图像大小是32708 …

java ftp apache-commons-net

1
推荐指数
1
解决办法
2785
查看次数

数据连接上的FTPSClient套接字超时

更新中...

抱歉实时调试.我整天都陷入困境,我想写出来让我更接近研究它......

我注意到我正在使用setUseEPSVwithIPv4(true)发送一个

EPSV
229 Entering Passive Mode (|||62110|)
Run Code Online (Sandbox Code Playgroud)

删除它让我更进一步,现在我得到了

Total Bytes To Send: 1033
PASV
227 Entering Passive Mode (xxx,xxx,xxx,42,242,189)
STOR /Inbound/Encrypted/TEST.pgp

File Transfer Failed at: 2013-11-21 18:33:07.846
Error Occurred Transmitting File to Remote System, aborting...

Host attempting data connection xxx.xxx.xxx.42 is not same as server xxx.xxx.xxx.67
java.io.IOException: Host attempting data connection xxx.xxx.92.42 is not same as server xxx.xxx.xxx.67
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:912)
at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:600)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:633)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624)150 Opening ASCII mode SSL data connection for /Inbound/Encrypted/TCONW.TEST.IN.pgp.

at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976)
at mycode.FTPConnection.sendFile(FTPConnection.java:667) …
Run Code Online (Sandbox Code Playgroud)

java ftps apache-commons-net

1
推荐指数
1
解决办法
6078
查看次数

用Java确定另一个国家的互联网时间

我正在开发一个将被世界各地的人们使用的Java应用程序.一项功能要求它显示澳大利亚墨尔本当前时间.

我找到了这个答案,并按如下方式调整了代码,但它返回了我当前的时间(如预期的那样).它使用Apache Commons Net库:

    try {
        String TIME_SERVER = "time-a.nist.gov";   
        NTPUDPClient timeClient = new NTPUDPClient();
        InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
        TimeInfo timeInfo = timeClient.getTime(inetAddress);
        long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
        return new Date(returnTime);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

如何修改此代码以返回墨尔本的时间,而不是我的时间?我也愿意接受其他解决方案来解决这个问题.

谢谢!

编辑:

根据Jon的建议,我使用了JodaTime库并构建了以下代码来解决问题.通过将澳大利亚/墨尔本更改为此处找到的任何时区,它可以用于其他时区.

    try {
        //Get the time for the current time zone.
        String TIME_SERVER = "time-a.nist.gov";   
        NTPUDPClient timeClient = new NTPUDPClient();
        InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
        TimeInfo timeInfo = timeClient.getTime(inetAddress);
        long returnTime …
Run Code Online (Sandbox Code Playgroud)

java time apache-commons apache-commons-net

0
推荐指数
1
解决办法
1165
查看次数

Apache commons-net FTP错误

我试图在java中实现ftp下载.我正在使用apache common-net library但是我得到了这个异常.我打印出下面的堆栈跟踪我不知道我错过了什么

org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:317)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
at org.apache.commons.net.ftp.FTP.pasv(FTP.java:1007)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:869)
at org.apache.commons.net.ftp.FTPClient._retrieveFile(FTPClient.java:1854)
at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1845)
Run Code Online (Sandbox Code Playgroud)

我有一个方法如下

  public void downloadFromFtp(Map<String, String> ftpMap, String sourceWithPath,
      String destinationFolder) throws IOException {

    String hostname = ftpMap.get("hostname");
    String username = ftpMap.get("username");
    String password = ftpMap.get("password");

    if (null == hostname || null == username || null == password) {
      throw new InvalidInputException(
          "Invalid RMS FTP hostname/username/password");
    }
    //Connect to ftp url
    ftpClient.connect(hostname, 21);
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

    //login …
Run Code Online (Sandbox Code Playgroud)

java ftp apache-commons apache-commons-net

0
推荐指数
1
解决办法
3874
查看次数

Java FTPS 无法检索文件列表(FileZilla 客户端工作正常)

我使用带有 Java 8 的 Apache Commons Net (v3.5) 连接到远程 FTPS 站点(即在 Internet 上)。我可以在我的 Windows 10 机器上轻松连接 FileZilla 客户端,但我的 Java 程序无法完成相同的步骤。我在谷歌上搜索了高低,但找不到根本原因。以下是我已经确认的事情:

  • 我确保 Java FTP 命令与 FileZilla 客户端的顺序完全相同。
  • 我在 PC 上禁用了 Windows 防火墙和防病毒软件
  • 我重新启用了 Windows 防火墙并启用了日志记录。使用 FileZilla 时,Windows 防火墙日志会在建立被动模式连接时列出 TCP 连接。我在 Java 程序中没有看到这样的条目。
  • 我在我的 PC 上安装了 FileZilla 服务器。在我取消选中“使用 PROT P 时需要在数据连接上恢复 TLS 会话”后,java 程序运行。Java 例外是不同的,所以我不相信这是一个确凿的证据。
  • 我成功地针对 test.rebex.com 服务器运行了相同的代码。

以下是代码,非常感谢您的任何想法:

import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;

public class testProgram {

  public static void main(String[] args) …
Run Code Online (Sandbox Code Playgroud)

java ftp ssl ftps apache-commons-net

0
推荐指数
1
解决办法
6675
查看次数

java ftp传输文件导致文件损坏

我是这种工作的新手,所以请帮助我。我将一个 xlsx 文件(一个 excel 文件)发送到服务器,我的代码中没有错误,或者在 ftp 服务器中,我在 xampp 中使用 filezilla。我在谷歌搜索并说它必须存储在一个 zip 文件中,但 zip 文件也已损坏。这是我的代码

 FTPClient upload= new FTPClient();
   File firstLocalFile = new File("C:/Users/user/desktop/sample.xlsx");
   InputStream inputStream = new FileInputStream(firstLocalFile);
   try {

       upload.connect("localhost");
       upload.login("user", "pass");
       upload.enterLocalPassiveMode();
       upload.storeFile("sample.zip", inputStream);
   } finally {
       try {
           upload.logout();
           upload.disconnect();
       } catch (Exception e) {
       }
   }
Run Code Online (Sandbox Code Playgroud)

我的问题有什么解决方案吗?

java ftp excel apache-commons-net

0
推荐指数
1
解决办法
1097
查看次数

FTP客户端可以控制FTP服务器超时设置吗?

我正在Java中使用Apache Commons-Net

我想要的是使用Java代码在客户端阶段设置FTP服务器的连接超时

例如:

如果我查看FTP服务器的vsftpd.conf设置文件,

有一个idle_session_timeout=600设置

我想知道FTP客户端是否可以使用Java代码控制此空闲超时

下面的方法,我尝试了但并非所有方法都有效

FTPClient.setControlKeepAliveTimeout(sec);
FTPClient.setConnectTimeout(ms);
FTPClient.setDataTimeout(ms);
FTPClient.connect();
FTPClient.setSoTimeout(ms);
Run Code Online (Sandbox Code Playgroud)

请帮我 :)

java ftp apache-commons-net

0
推荐指数
1
解决办法
65
查看次数

标签 统计

apache-commons-net ×11

java ×10

ftp ×5

ftps ×4

apache-commons ×2

ssl ×2

excel ×1

scala ×1

time ×1