Android FTP 错误 - 425 无法打开数据连接

标签 android ftp

我正在使用它来上传一些文件。如果我在本地连接中它会工作,但如果我使用外部连接,我会收到此消息:425 无法打开数据连接。 来自 ftp 服务器。

我使用 org.apache.commons.net.ftp.FTPClient 和 org.apache.commons.net.ftp.FTPFile 库。

public static String gravaImagem(String photoFile) {
    FTPClient mFtp = new FTPClient();
    try {
    mFtp.connect(FTPHOST, PORTA);
    mFtp.login(USUARIO, SENHA);
    mFtp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
    mFtp.setFileType(FTPClient.BINARY_FILE_TYPE);
    String origem = Environment.getExternalStorageDirectory().getPath()+File.separator+"Pictures"+File.separator+"ImageSec"+File.separator+photoFile;
    FileInputStream fis = new FileInputStream(origem);
    mFtp.storeFile(photoFile, fis);
    mFtp.logout();
    mFtp.disconnect();
    } catch (SocketException e) {
    e.printStackTrace();
    return "Fail. (ERR#CON3)";
    } catch (IOException e) {
    e.printStackTrace();
    return "Fail. (ERR#CON4)";
    }
    return "Imagem enviada ao servidor.";
}

调试显示没有异常。

最佳答案

来自互联网:

First - the most common solution: change the active/passive mode settings. But that might not work, and if it does its only a band-aid covering up the real problem.

As I've mentioned in the past, one of the most common reasons that this error occurs is a misconfiguration of the FTP server software itself, related to SSL connections and firewalls, in which the connection tries to establish itself on a bogus ip address. Read more about FTP SSL through a NAT firewall here, some potential solutions are included.

There are other less likely causes, such as:

  • The server is configured to always use the same port for passive mode connections, or the client is configured to always use the same port for active mode connections, although in this case usually the software in question should raise a different error first, but I've seen this happen.
  • In passive mode, the firewall in front of the FTP server doesn't have the correct ports open. So the server tells the client to connect to ipaddress 1.2.3.4 on port x, but the firewall doesn't allow incoming connections on port x. Most firewalls are smart enough to open up the port when it sees the PASV response. Vice versa for active mode and the firewall in front of the FTP client.

来 self : 我在 andoird 上使用过这个库,它运行良好,所以请参阅我的复制/粘贴部分。

关于Android FTP 错误 - 425 无法打开数据连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17351695/

相关文章:

android - Android Viewpager 中图像的连续翻转

android - 在 Android 中构建用户界面 - View 与 XML

c# - Unity3D C# 计时器以毫秒为单位显示

android - Android中的内存分析器工具?

linux - 检查文件在 FTP 服务器上是否可用

google-chrome-extension - Chrome 操作系统 : how to enable direct SFTP access in the Files app/Pixelbook Review

android - 为什么我们使用xml?

c - FTP 程序,客户端请求服务器上的文件

iOS:使用 PDF 下载的应用程序,建议使用哪种方法? (ftp,休息, SOAP ,..)

c# 将ftp服务器上的图片直接加载到图片框中,无需下载