@@ -57,6 +57,7 @@ class ControlConnectHandler
57
57
private byte [] dataSocketPendingByteArray =null ; //!< 数据套接字数据内容 排队。
58
58
private String currentWorkingDirectory ="/" ; //!< 当前工作目录
59
59
private int data_port =1544 ; //!< 数据连接端口。
60
+ private String ip ; //!< ip
60
61
private boolean allowActiveMode =true ; //!< 是否允许主动模式。
61
62
private File writingFile ; //!< 当前正在写入的文件。
62
63
private boolean isUploading =false ; //!< 是否正在上传。陈欣
@@ -102,16 +103,17 @@ private void receiveDataSocket( ByteBufferList bb)
102
103
{
103
104
e .printStackTrace ();
104
105
}
105
- } //private void receiveDataSocket( ByteBufferList bb)
106
+ } // private void receiveDataSocket( ByteBufferList bb)
106
107
107
- public ControlConnectHandler (Context context , boolean allowActiveMode , InetAddress host )
108
+ public ControlConnectHandler (Context context , boolean allowActiveMode , InetAddress host , String ip )
108
109
{
109
110
this .context =context ;
110
111
this .allowActiveMode =allowActiveMode ;
111
112
this .host =host ;
113
+ this .ip =ip ; // Remember ip for data server.
112
114
113
- setupDataServer (); // 启动数据传输服务器。
114
- }
115
+ setupDataServer (); // 启动数据传输服务器。
116
+ }
115
117
116
118
/**
117
119
* 打开指向客户端特定端口的连接。
@@ -386,16 +388,22 @@ else if (command.equals("TYPE")) // 传输类型
386
388
else if (command .equals ("PASV" )) // 被动传输
387
389
{
388
390
setupDataServer (); // 初始化数据服务器。
389
-
390
- WifiManager wifiManager = (WifiManager ) context .getSystemService (Context .WIFI_SERVICE );
391
- String ipAddress = Formatter .formatIpAddress (wifiManager .getConnectionInfo ().getIpAddress ());
392
391
393
- String ip = ipAddress .replace ("." , "," );
394
-
392
+ String ipAddress = ip ;
393
+
394
+
395
+ if (ipAddress ==null ) // Have not set ip.
396
+ {
397
+ WifiManager wifiManager = (WifiManager ) context .getSystemService (Context .WIFI_SERVICE );
398
+ ipAddress = Formatter .formatIpAddress (wifiManager .getConnectionInfo ().getIpAddress ());
399
+ } // else // Not set ip.
400
+
401
+ String ipString = ipAddress .replace ("." , "," );
402
+
395
403
int port256 =data_port /256 ;
396
404
int portModule =data_port -port256 *256 ;
397
405
398
- String replyString ="227 Entering Passive Mode (" +ip +"," +port256 +"," +portModule +") " ; // 回复内容。
406
+ String replyString ="227 Entering Passive Mode (" +ipString +"," +port256 +"," +portModule +") " ; // 回复内容。
399
407
400
408
Log .d (TAG , "reply string: " + replyString ); //Debug.
401
409
@@ -941,9 +949,6 @@ public void onCompleted(Exception ex)
941
949
}
942
950
});
943
951
944
- //发送初始命令:
945
- // send_data "220 \n"
946
-
947
952
binaryStringSender .sendStringInBinaryMode ("220 StupidBeauty FtpServer" ); // 发送回复内容。
948
953
} //private void handleAccept(final AsyncSocket socket)
949
954
@@ -958,8 +963,6 @@ private void setupDataServer()
958
963
959
964
data_port =randomIndex ;
960
965
961
- // try // 绑定端口。
962
- // {
963
966
AsyncServer .getDefault ().listen (host , data_port , new ListenCallback ()
964
967
{
965
968
@ Override
@@ -979,9 +982,6 @@ public void onCompleted(Exception ex)
979
982
{
980
983
if (ex != null )
981
984
{
982
- // 09-07 07:57:47.473 18998 19023 W System.err: java.lang.RuntimeException: java.net.BindException: Address already in use
983
-
984
- // throw new RuntimeException(ex);
985
985
ex .printStackTrace ();
986
986
987
987
setupDataServer (); // 重新初始化。
0 commit comments