OSDN Git Service

Fix bugs of corruption on resuming downloading files larger than 4GB.
[ffftp/ffftp.git] / connect.c
index af55002..904fd0d 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -586,7 +586,8 @@ static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List)
 \r
        *Fire = FwallDefault;\r
        *Pasv = PasvDefault;\r
-       *List = NO;\r
+       // NLSTを送ってしまうバグ修正(ただしNLSTを使うべきホストへクイック接続できなくなる)\r
+//     *List = NO;\r
 \r
        i = 0;\r
        while(CopyHostFromList(i, &Tmp) == FFFTP_SUCCESS)\r
@@ -926,24 +927,15 @@ static void SaveCurrentSetToHistory(void)
 int ReConnectCmdSkt(void)\r
 {\r
        int Sts;\r
-       SOCKET s;\r
 \r
 \r
        // 同時接続対応\r
 //     if(CmdCtrlSocket != TrnCtrlSocket)\r
-//             do_closesocket(TrnCtrlSocket);\r
-//     TrnCtrlSocket = INVALID_SOCKET;\r
-       s = TrnCtrlSocket;\r
+       if(CmdCtrlSocket != TrnCtrlSocket && TrnCtrlSocket != INVALID_SOCKET)\r
+               do_closesocket(TrnCtrlSocket);\r
        TrnCtrlSocket = INVALID_SOCKET;\r
-       if(CmdCtrlSocket != s && s != INVALID_SOCKET)\r
-               do_closesocket(s);\r
 \r
-       // 同時接続対応\r
-//     Sts = ReConnectSkt(&CmdCtrlSocket);\r
-       s = CmdCtrlSocket;\r
-       CmdCtrlSocket = INVALID_SOCKET;\r
-       Sts = ReConnectSkt(&s);\r
-       CmdCtrlSocket = s;\r
+       Sts = ReConnectSkt(&CmdCtrlSocket);\r
 \r
        TrnCtrlSocket = CmdCtrlSocket;\r
 \r
@@ -1270,7 +1262,8 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                        Fwall = FWALL_NONE;\r
 \r
                TryConnect = YES;\r
-               CancelFlg = NO;\r
+               // 暗号化通信対応\r
+//             CancelFlg = NO;\r
 #if 0\r
 //             WSASetBlockingHook(BlkHookFnc);\r
 #endif\r
@@ -1302,20 +1295,10 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
 //                                     ;\r
                                if(CryptMode == CRYPT_FTPIS)\r
                                {\r
-                                       if(AttachSSL(ContSock))\r
+                                       if(AttachSSL(ContSock, INVALID_SOCKET))\r
                                        {\r
                                                while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
                                                        ;\r
-                                               if((Sts = command(ContSock, Reply, &CancelFlg, "PBSZ 0")) == 200)\r
-                                               {\r
-                                                       if((Sts = command(ContSock, Reply, &CancelFlg, "PROT P")) == 200)\r
-                                                       {\r
-                                                       }\r
-                                                       else\r
-                                                               Sts = FTP_ERROR;\r
-                                               }\r
-                                               else\r
-                                                       Sts = FTP_ERROR;\r
                                        }\r
                                        else\r
                                                Sts = FTP_ERROR;\r
@@ -1417,7 +1400,7 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                                                {\r
                                                                        if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, &CancelFlg, "AUTH TLS")) == 234)\r
                                                                        {\r
-                                                                               if(AttachSSL(ContSock))\r
+                                                                               if(AttachSSL(ContSock, INVALID_SOCKET))\r
                                                                                {\r
                                                                                        if((Sts = command(ContSock, Reply, &CancelFlg, "PBSZ 0")) == 200)\r
                                                                                        {\r
@@ -1542,6 +1525,9 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                // MLST対応\r
                                if(strstr(Reply, " MLST ") || strstr(Reply, " MLSD "))\r
                                        HostData->Feature |= FEATURE_MLSD;\r
+                               // IPv6対応\r
+                               if(strstr(Reply, " EPRT ") || strstr(Reply, " EPSV "))\r
+                                       HostData->Feature |= FEATURE_EPRT | FEATURE_EPSV;\r
                        }\r
                        // UTF-8対応\r
                        if(HostData->NameKanjiCode == KANJI_AUTO && (HostData->Feature & FEATURE_UTF8))\r
@@ -1563,25 +1549,26 @@ static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass,
 {\r
        SOCKET ContSock;\r
        ContSock = INVALID_SOCKET;\r
-       if(ContSock == INVALID_SOCKET && HostData->UseSFTP == YES)\r
+       CancelFlg = NO;\r
+       if(CancelFlg == NO && ContSock == INVALID_SOCKET && HostData->UseSFTP == YES)\r
        {\r
                SetTaskMsg(MSGJPN317);\r
                if((ContSock = DoConnectCrypt(CRYPT_SFTP, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security)) != INVALID_SOCKET)\r
                        HostData->CryptMode = CRYPT_SFTP;\r
        }\r
-//     if(ContSock == INVALID_SOCKET && HostData->UseFTPIS == YES)\r
-//     {\r
-//             SetTaskMsg(MSGJPN316);\r
-//             if((ContSock = DoConnectCrypt(CRYPT_FTPIS, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security)) != INVALID_SOCKET)\r
-//                     HostData->CryptMode = CRYPT_FTPIS;\r
-//     }\r
-       if(ContSock == INVALID_SOCKET && HostData->UseFTPES == YES)\r
+       if(CancelFlg == NO && ContSock == INVALID_SOCKET && HostData->UseFTPIS == YES)\r
+       {\r
+               SetTaskMsg(MSGJPN316);\r
+               if((ContSock = DoConnectCrypt(CRYPT_FTPIS, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security)) != INVALID_SOCKET)\r
+                       HostData->CryptMode = CRYPT_FTPIS;\r
+       }\r
+       if(CancelFlg == NO && ContSock == INVALID_SOCKET && HostData->UseFTPES == YES)\r
        {\r
                SetTaskMsg(MSGJPN315);\r
                if((ContSock = DoConnectCrypt(CRYPT_FTPES, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security)) != INVALID_SOCKET)\r
                        HostData->CryptMode = CRYPT_FTPES;\r
        }\r
-       if(ContSock == INVALID_SOCKET && HostData->UseNoEncryption == YES)\r
+       if(CancelFlg == NO && ContSock == INVALID_SOCKET && HostData->UseNoEncryption == YES)\r
        {\r
                SetTaskMsg(MSGJPN314);\r
                if((ContSock = DoConnectCrypt(CRYPT_NONE, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security)) != INVALID_SOCKET)\r
@@ -2348,6 +2335,11 @@ int AskUseSFTP(void)
        return(CurHost.UseSFTP);\r
 }\r
 \r
+char *AskPrivateKey(void)\r
+{\r
+       return(CurHost.PrivateKey);\r
+}\r
+\r
 // 同時接続対応\r
 int AskMaxThreadCount(void)\r
 {\r
@@ -2366,3 +2358,9 @@ int AskUseMLSD(void)
        return(CurHost.UseMLSD);\r
 }\r
 \r
+// IPv6対応\r
+int AskUseIPv6(void)\r
+{\r
+       return(CurHost.UseIPv6);\r
+}\r
+\r