Forefront TMG vs java和php(ftp)

时间:2013-12-16 09:58:55

标签: java php sockets ftp firewall

我在ForeFront TMG 7.0和公共远程ftp服务器后面有一台计算机。已安装TMG客户端。 Windows防火墙已关闭。 防病毒:McAfee病毒扫描企业版(8.8)+ AntySpyware Enterprize(8.8)+无插件。 防病毒测试开启和关闭。

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

对于Java,我收到ConnectionRefused错误:

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客户端(主动/被动 - 本地/远程/两者)
  • Apache FTPS客户端(所有varians active | passive)
  • Sauron FTP客户端(相同)
  • 套接字套接字=新套接字(主机,21);

Semetimes它在等待5分钟后拖出连接超时。而错误是超时异常。 所有varians都使用直接连接,全局代理,ftp代理,http代理及其所有组合进行测试。 所有变体都通过IP和主机名进行测试。

无法连接的Php代码示例:

<?php

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

?>

但是filezilla连接没有问题。 Explorer连接没有问题。 Go-written程序连接没有问题。

任何可以阻止java和php的想法?如何确定阻止JRE和Apache的策略或程序设置?

2 个答案:

答案 0 :(得分:0)

您可以尝试使用下面的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";
}
?>

答案 1 :(得分:0)

我只有两美分。这是我已经使用两年的工作 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());
        
        
                    }
        
        
                }
        
        
            }
    }