Forefront TMG vs java and php (ftp)

2022-08-30 22:28:47

我在ForeFront TMG 7.0后面有一台计算机和一个公共远程FTP服务器。已安装 TMG 客户端。Windows 防火墙已关闭。防病毒软件:迈克菲病毒扫描企业版 (8.8) + AntySpyware Enterprize (8.8) + 无附加组件。防病毒软件已经过断断续续的测试。

它无法通过Java和Php连接到服务器,Filezilla,explorer.exe和Go编写的程序连接没有问题。

对于Java,我得到连接已熔断错误:

java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:182)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:203)

无论我如何尝试通过Java进行连接:

  • Apache FTP Client(主动/被动 - 本地/远程/两者)
  • Apache FTPS Client (all varians active|passive)
  • Sauron FTP Client (相同)
  • 套接字套接字 = 新套接字(主机, 21);

Semetimes 它会在等待 5 分钟后增加连接超时。错误是超时异常。所有 varian 都经过直接连接、全局代理、ftp 代理、http 代理及其所有组合的测试。所有变体都通过 IP 和主机名进行测试。

无法连接的 Php 代码示例:

<?php

  $host = "ftphost";
  $connect = ftp_connect($host,21);
  if(!$connect)
  {
    echo("Error: $host");
    exit;
  }
  else
  {
    echo("Cheers: $host");  
  }

?>

但是FileZilla连接没有问题。资源管理器连接没有问题。Go编写的程序连接没有问题。

任何想法可以阻止Java和PHP?如何找出阻止 JRE 和 Apache 的策略或程序设置?


答案 1

您可以尝试使用 PHP 脚本调试问题,如下所示:

<?php
$host = "xx.xx.xx.xx";
$ftpUser = "annonymous";
$ftpPass = null;
$checkPort = @fsockopen($host, 21, $errno, $errstr, 10);
if($checkPort!==false){
    echo "can able to connect ftp server";
    $conn_id = ftp_connect($host);
    if($conn_id!==false){
    echo "\n Ftp server available and connected trying to logged in";
        $loginStatus = ftp_login($conn_id, $ftpUser, $ftpPass);
        if($loginStatus!==false){
            echo "\n Connected to ftp";
        } else {
            echo "\n Please check credentials";
        }
    }
} else {
    echo "server can't reach to ftp server";
}
?>

答案 2

只是我的两分钱。这是我的工作Ftp代码,我已经使用了两年,主要问题是服务器端,如果你启用被动模式,那么你需要在防火墙中打开一系列被动端口,如2000:4000,以保持连接不被破坏。此外,请确保为这些被动端口配置了 Ftp 服务器。您可以在 https://slacksite.com/other/ftp.html 中阅读更多内容

import config.AppConfigPropertyReader;
        
        import model.FtpClients;
        import org.apache.commons.io.FileUtils;
        import org.apache.commons.net.ftp.FTP;
        import org.apache.commons.net.ftp.FTPReply;
        import org.apache.commons.net.ftp.FTPSClient;
        import org.apache.log4j.Logger;
        
        import java.io.File;
        import java.io.FileInputStream;
        import java.io.IOException;
        import java.io.InputStream;
        import java.util.ArrayList;
        import java.util.List;
        
        public class ConnectRemote {
        
            private static Logger logger = Logger.getLogger(ConnectRemote.class);
            private static String RemoteFtpLogServerHost = AppConfigPropertyReader.getProperty("RemoteFtpLogServerHost");
            private static String RemoteFtpLogServerTomcatLog = AppConfigPropertyReader.getProperty("RemoteFtpLogServerTomcatLog");
            private static String RemoteFtpLogServerTomcatLogPassword = AppConfigPropertyReader.getProperty("RemoteFtpLogServerTomcatLogPassword");
            private static String LocalTomcatSistemLogPath = AppConfigPropertyReader.getProperty("LocalTomcatSistemLogPath");
        
        
            public static void starttransfers() {
        
                List<FtpClients> ftpuserlist = new ArrayList<FtpClients>();
        
                ftpuserlist.add(new FtpClients(RemoteFtpLogServerTomcatLogPassword, RemoteFtpLogServerTomcatLog, LocalTomcatSistemLogPath));
        
                for (FtpClients ftpuser : ftpuserlist) {
        
                    try {
        
                        ftps = new FTPSClient();
                        //ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
                      
                        ftps.connect(RemoteFtpLogServerHost, 21);
                        int reply = ftps.getReplyCode();
                        if (!FTPReply.isPositiveCompletion(reply)) {
                            ftps.disconnect();
                            throw new IOException("Exception in connecting to FTPS Server");
                        }
                        if (ftps.login(ftpuser.getUser(), ftpuser.getPassword())) {
        
                            ftps.execPBSZ(0);
                            //ftps.execPROT("P"); You have to use reuse ssl enabled ftp server
                            ftps.setBufferSize(1024000);
                            ftps.changeWorkingDirectory("/");
                            ftps.setFileType(FTP.BINARY_FILE_TYPE);
                            ftps.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE);
                            ftps.enterLocalPassiveMode();
                            ftps.setControlKeepAliveTimeout(300);
                            
                            //do your logic 
        
                            if (ftps.isConnected()) {
                                try {
                                    ftps.logout();
                                    ftps.disconnect();
                                    ftps = null;
                                    ftpuserlist.clear();
        
                                } catch (IOException e) {
                                    logger.error("Ftps Client Closing " + e.getMessage());
                                }
                            }
        
                        } else {
        
                            logger.error("Cannot Login to Remote Ftps Server");
        
                        }
        
        
                    } catch (Exception e) {
        
                        e.printStackTrace();
                        logger.error("Exception" + e.getMessage());
        
        
                    }
        
        
                }
        
        
            }
    }

推荐