OSDN Git Service

Fix bugs of corruption on resuming downloading files larger than 4GB.
[ffftp/ffftp.git] / connect.c
index b37571c..904fd0d 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -57,7 +57,10 @@ static int SendInitCommand(char *Cmd);
 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List);\r
 static void SaveCurrentSetToHistory(void);\r
 static int ReConnectSkt(SOCKET *Skt);\r
-static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
+// 暗号化通信対応\r
+//static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
+static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
+static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
 static int CheckOneTimePassword(char *Pass, char *Reply, int Type);\r
 static BOOL CALLBACK BlkHookFnc(void);\r
 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port);\r
@@ -159,7 +162,9 @@ void ConnectProc(int Type, int Num)
                                Save = YES;\r
 \r
                        DisableUserOpe();\r
-                       CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security);\r
+                       // 暗号化通信対応\r
+//                     CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security);\r
+                       CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security);\r
                        TrnCtrlSocket = CmdCtrlSocket;\r
 \r
                        if(CmdCtrlSocket != INVALID_SOCKET)\r
@@ -238,7 +243,9 @@ void QuickConnectProc(void)
                        SetSyncMoveMode(CurHost.SyncMove);\r
 \r
                        DisableUserOpe();\r
-                       CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+                       // 暗号化通信対応\r
+//                     CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+                       CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
                        TrnCtrlSocket = CmdCtrlSocket;\r
 \r
                        if(CmdCtrlSocket != INVALID_SOCKET)\r
@@ -410,7 +417,9 @@ void DirectConnectProc(char *unc, int Kanji, int Kana, int Fkanji, int TrMode)
                }\r
 \r
                DisableUserOpe();\r
-               CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+               // 暗号化通信対応\r
+//             CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+               CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
                TrnCtrlSocket = CmdCtrlSocket;\r
 \r
                if(CmdCtrlSocket != INVALID_SOCKET)\r
@@ -486,7 +495,9 @@ void HistoryConnectProc(int MenuCmd)
                        DispTransferType();\r
 \r
                        DisableUserOpe();\r
-                       CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+                       // 暗号化通信対応\r
+//                     CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
+                       CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
                        TrnCtrlSocket = CmdCtrlSocket;\r
 \r
                        if(CmdCtrlSocket != INVALID_SOCKET)\r
@@ -575,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
@@ -916,7 +928,10 @@ int ReConnectCmdSkt(void)
 {\r
        int Sts;\r
 \r
-       if(CmdCtrlSocket != TrnCtrlSocket)\r
+\r
+       // 同時接続対応\r
+//     if(CmdCtrlSocket != TrnCtrlSocket)\r
+       if(CmdCtrlSocket != TrnCtrlSocket && TrnCtrlSocket != INVALID_SOCKET)\r
                do_closesocket(TrnCtrlSocket);\r
        TrnCtrlSocket = INVALID_SOCKET;\r
 \r
@@ -942,6 +957,46 @@ int ReConnectCmdSkt(void)
 //{\r
 //     return(ReConnectSkt(&TrnCtrlSocket));\r
 //}\r
+// 同時接続対応\r
+int ReConnectTrnSkt(SOCKET *Skt)\r
+{\r
+//     char Path[FMAX_PATH+1];\r
+       int Sts;\r
+       // 暗号化通信対応\r
+       HOSTDATA HostData;\r
+\r
+       Sts = FFFTP_FAIL;\r
+\r
+       SetTaskMsg(MSGJPN003);\r
+\r
+//     DisableUserOpe();\r
+       /* 現在のソケットは切断 */\r
+       if(*Skt != INVALID_SOCKET)\r
+               do_closesocket(*Skt);\r
+       /* 再接続 */\r
+       // 暗号化通信対応\r
+       HostData = CurHost;\r
+       if(HostData.CryptMode != CRYPT_NONE)\r
+               HostData.UseNoEncryption = NO;\r
+       if(HostData.CryptMode != CRYPT_FTPES)\r
+               HostData.UseFTPES = NO;\r
+       if(HostData.CryptMode != CRYPT_FTPIS)\r
+               HostData.UseFTPIS = NO;\r
+       if(HostData.CryptMode != CRYPT_SFTP)\r
+               HostData.UseSFTP = NO;\r
+//     if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
+       if((*Skt = DoConnect(&HostData, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
+       {\r
+//             AskRemoteCurDir(Path, FMAX_PATH);\r
+//             DoCWD(Path, YES, YES, YES);\r
+               Sts = FFFTP_SUCCESS;\r
+       }\r
+       else\r
+               SoundPlay(SND_ERROR);\r
+\r
+//     EnableUserOpe();\r
+       return(Sts);\r
+}\r
 \r
 \r
 /*----- 回線の再接続 ----------------------------------------------------------\r
@@ -968,7 +1023,9 @@ static int ReConnectSkt(SOCKET *Skt)
        if(*Skt != INVALID_SOCKET)\r
                do_closesocket(*Skt);\r
        /* 再接続 */\r
-       if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
+       // 暗号化通信対応\r
+//     if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
+       if((*Skt = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
        {\r
                AskRemoteCurDir(Path, FMAX_PATH);\r
                DoCWD(Path, YES, YES, YES);\r
@@ -1028,8 +1085,11 @@ void SktShareProh(void)
 \r
 //SetTaskMsg("############### SktShareProh");\r
 \r
-               CmdCtrlSocket = INVALID_SOCKET;\r
-               ReConnectSkt(&CmdCtrlSocket);\r
+               // 同時接続対応\r
+               // 転送スレッドがソケットを各自で用意\r
+               // TrnCtrlSocketはメインスレッド以外から使用されない\r
+//             CmdCtrlSocket = INVALID_SOCKET;\r
+//             ReConnectSkt(&CmdCtrlSocket);\r
        }\r
        return;\r
 }\r
@@ -1050,8 +1110,8 @@ int AskShareProh(void)
        int Sts;\r
 \r
        Sts = YES;\r
-       if(CmdCtrlSocket == TrnCtrlSocket)\r
-               Sts = NO;\r
+//     if(CmdCtrlSocket == TrnCtrlSocket)\r
+//             Sts = NO;\r
 \r
        return(Sts);\r
 }\r
@@ -1174,7 +1234,8 @@ int AskConnecting(void)
 *                      none    Connect host →                                              USER user(h) →      PASS pass(h) → ACCT acct\r
 *----------------------------------------------------------------------------*/\r
 \r
-static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
+// 暗号化通信対応\r
+static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
 {\r
        int Sts;\r
        int Flg;\r
@@ -1190,143 +1251,164 @@ static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port
        char TmpBuf[ONELINE_BUF_SIZE];\r
        struct linger LingerOpt;\r
 \r
-       if(Fwall == YES)\r
-               Fwall = FwallType;\r
-       else\r
-               Fwall = FWALL_NONE;\r
+       // 暗号化通信対応\r
+       ContSock = INVALID_SOCKET;\r
 \r
-       TryConnect = YES;\r
-       CancelFlg = NO;\r
+       if(CryptMode == CRYPT_NONE || CryptMode == CRYPT_FTPES || CryptMode == CRYPT_FTPIS)\r
+       {\r
+               if(Fwall == YES)\r
+                       Fwall = FwallType;\r
+               else\r
+                       Fwall = FWALL_NONE;\r
+\r
+               TryConnect = YES;\r
+               // 暗号化通信対応\r
+//             CancelFlg = NO;\r
 #if 0\r
-//     WSASetBlockingHook(BlkHookFnc);\r
+//             WSASetBlockingHook(BlkHookFnc);\r
 #endif\r
 \r
-       ContSock = INVALID_SOCKET;\r
+               ContSock = INVALID_SOCKET;\r
 \r
-       HostPort = Port;\r
-       Tmp = Host;\r
-       if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
-          (Fwall == FWALL_SIDEWINDER) ||\r
-          (Fwall == FWALL_FU_FP))\r
-       {\r
-               Tmp = FwallHost;\r
-               Port = FwallPort;\r
-       }\r
+               HostPort = Port;\r
+               Tmp = Host;\r
+               if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
+                  (Fwall == FWALL_SIDEWINDER) ||\r
+                  (Fwall == FWALL_FU_FP))\r
+               {\r
+                       Tmp = FwallHost;\r
+                       Port = FwallPort;\r
+               }\r
 \r
-       if(strlen(Tmp) != 0)\r
-       {\r
-               if((ContSock = connectsock(Tmp, Port, "", &CancelFlg)) != INVALID_SOCKET)\r
+               if(strlen(Tmp) != 0)\r
                {\r
-                       // バッファを無効\r
+                       if((ContSock = connectsock(Tmp, Port, "", &CancelFlg)) != INVALID_SOCKET)\r
+                       {\r
+                               // バッファを無効\r
 #ifdef DISABLE_CONTROL_NETWORK_BUFFERS\r
-                       int BufferSize = 0;\r
-                       setsockopt(ContSock, SOL_SOCKET, SO_SNDBUF, (char*)&BufferSize, sizeof(int));\r
-                       setsockopt(ContSock, SOL_SOCKET, SO_RCVBUF, (char*)&BufferSize, sizeof(int));\r
+                               int BufferSize = 0;\r
+                               setsockopt(ContSock, SOL_SOCKET, SO_SNDBUF, (char*)&BufferSize, sizeof(int));\r
+                               setsockopt(ContSock, SOL_SOCKET, SO_RCVBUF, (char*)&BufferSize, sizeof(int));\r
 #endif\r
-                       while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
-                               ;\r
-\r
-                       if(Sts == FTP_COMPLETE)\r
-                       {\r
-                               Flg = 1;\r
-                               if(setsockopt(ContSock, SOL_SOCKET, SO_OOBINLINE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
-                                       ReportWSError("setsockopt", WSAGetLastError());\r
-                               // データ転送用ソケットのTCP遅延転送が無効されているので念のため\r
-                               if(setsockopt(ContSock, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
-                                       ReportWSError("setsockopt", WSAGetLastError());\r
-#pragma aaa\r
-                               Flg = 1;\r
-                               if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
-                                       ReportWSError("setsockopt", WSAGetLastError());\r
-                               LingerOpt.l_onoff = 1;\r
-                               LingerOpt.l_linger = 90;\r
-                               if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
-                                       ReportWSError("setsockopt", WSAGetLastError());\r
-///////\r
-\r
-\r
-                               /*===== 認証を行なう =====*/\r
-\r
-                               Sts = FTP_COMPLETE;\r
-                               if((Fwall == FWALL_FU_FP_SITE) ||\r
-                                  (Fwall == FWALL_FU_FP_USER) ||\r
-                                  (Fwall == FWALL_FU_FP))\r
+                               // FTPIS対応\r
+//                             while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
+//                                     ;\r
+                               if(CryptMode == CRYPT_FTPIS)\r
                                {\r
-                                       if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
+                                       if(AttachSSL(ContSock, INVALID_SOCKET))\r
                                        {\r
-                                               CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
-                                               Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
+                                               while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
+                                                       ;\r
                                        }\r
+                                       else\r
+                                               Sts = FTP_ERROR;\r
                                }\r
-                               else if(Fwall == FWALL_SIDEWINDER)\r
-                               {\r
-                                       Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
-                               }\r
-                               if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
+                               else\r
                                {\r
-                                       SetTaskMsg(MSGJPN006);\r
-                                       DoClose(ContSock);\r
-                                       ContSock = INVALID_SOCKET;\r
+                                       while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
+                                               ;\r
                                }\r
-                               else\r
+\r
+                               if(Sts == FTP_COMPLETE)\r
                                {\r
-                                       if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
+                                       Flg = 1;\r
+                                       if(setsockopt(ContSock, SOL_SOCKET, SO_OOBINLINE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
+                                               ReportWSError("setsockopt", WSAGetLastError());\r
+                                       // データ転送用ソケットのTCP遅延転送が無効されているので念のため\r
+                                       if(setsockopt(ContSock, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
+                                               ReportWSError("setsockopt", WSAGetLastError());\r
+//#pragma aaa\r
+                                       Flg = 1;\r
+                                       if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
+                                               ReportWSError("setsockopt", WSAGetLastError());\r
+                                       LingerOpt.l_onoff = 1;\r
+                                       LingerOpt.l_linger = 90;\r
+                                       if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
+                                               ReportWSError("setsockopt", WSAGetLastError());\r
+///////\r
+\r
+\r
+                                       /*===== 認証を行なう =====*/\r
+\r
+                                       Sts = FTP_COMPLETE;\r
+                                       if((Fwall == FWALL_FU_FP_SITE) ||\r
+                                          (Fwall == FWALL_FU_FP_USER) ||\r
+                                          (Fwall == FWALL_FU_FP))\r
                                        {\r
-                                               Flg = 0;\r
-                                               if(Fwall == FWALL_OPEN)\r
-                                                       Flg = 2;\r
-                                               if(FwallLower == YES)\r
-                                                       Flg++;\r
-\r
-                                               if(HostPort == PORT_NOR)\r
-                                                       Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
-                                               else\r
-                                                       Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
+                                               if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
+                                               {\r
+                                                       CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
+                                                       Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
+                                               }\r
+                                       }\r
+                                       else if(Fwall == FWALL_SIDEWINDER)\r
+                                       {\r
+                                               Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
                                        }\r
-\r
                                        if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
                                        {\r
-                                               SetTaskMsg(MSGJPN007, Host);\r
+                                               SetTaskMsg(MSGJPN006);\r
                                                DoClose(ContSock);\r
                                                ContSock = INVALID_SOCKET;\r
                                        }\r
                                        else\r
                                        {\r
-                                               Anony = NO;\r
-                                               if((strlen(User) != 0) || \r
-                                                  (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                               if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
                                                {\r
-                                                       if(Anony == YES)\r
-                                                       {\r
-                                                               strcpy(User, "anonymous");\r
-                                                               strcpy(Pass, UserMailAdrs);\r
-                                                       }\r
+                                                       Flg = 0;\r
+                                                       if(Fwall == FWALL_OPEN)\r
+                                                               Flg = 2;\r
+                                                       if(FwallLower == YES)\r
+                                                               Flg++;\r
+\r
+                                                       if(HostPort == PORT_NOR)\r
+                                                               Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
+                                                       else\r
+                                                               Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
+                                               }\r
 \r
-                                                       if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
+                                               if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
+                                               {\r
+                                                       SetTaskMsg(MSGJPN007, Host);\r
+                                                       DoClose(ContSock);\r
+                                                       ContSock = INVALID_SOCKET;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       Anony = NO;\r
+                                                       if((strlen(User) != 0) || \r
+                                                          (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
                                                        {\r
-                                                               if(HostPort == PORT_NOR)\r
-                                                                       sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
+                                                               if(Anony == YES)\r
+                                                               {\r
+                                                                       strcpy(User, "anonymous");\r
+                                                                       strcpy(Pass, UserMailAdrs);\r
+                                                               }\r
+\r
+                                                               if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
+                                                               {\r
+                                                                       if(HostPort == PORT_NOR)\r
+                                                                               sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
+                                                                       else\r
+                                                                               sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
+                                                               }\r
                                                                else\r
-                                                                       sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
-                                                       }\r
-                                                       else\r
-                                                               strcpy(Buf, User);\r
+                                                                       strcpy(Buf, User);\r
 \r
-                                                       // FTPES対応\r
-                                                       // 2回以上呼ばれる事があるため既にFTPESで接続していても再確認\r
-                                                       if(CurHost.CryptMode == CRYPT_NONE || CurHost.CryptMode == CRYPT_FTPES)\r
-                                                       {\r
-                                                               if(IsOpenSSLLoaded() && CurHost.UseFTPES == YES && (Sts = command(ContSock, Reply, &CancelFlg, "AUTH TLS")) == 234)\r
+                                                               // FTPES対応\r
+                                                               if(CryptMode == CRYPT_FTPES)\r
                                                                {\r
-                                                                       // SSLに切り替え\r
-                                                                       SetTaskMsg(MSGJPN315);\r
-                                                                       CurHost.CryptMode = CRYPT_FTPES;\r
-                                                                       if(AttachSSL(ContSock))\r
+                                                                       if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, &CancelFlg, "AUTH TLS")) == 234)\r
                                                                        {\r
-                                                                               if((Sts = command(ContSock, Reply, &CancelFlg, "PBSZ 0")) == 200)\r
+                                                                               if(AttachSSL(ContSock, INVALID_SOCKET))\r
                                                                                {\r
-                                                                                       if((Sts = command(ContSock, Reply, &CancelFlg, "PROT P")) == 200)\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
@@ -1337,106 +1419,164 @@ static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port
                                                                        else\r
                                                                                Sts = FTP_ERROR;\r
                                                                }\r
-                                                               else\r
-                                                               {\r
-                                                                       // 暗号化なし\r
-                                                                       CurHost.CryptMode = CRYPT_NONE;\r
-                                                                       SetTaskMsg(MSGJPN314);\r
-                                                               }\r
-                                                       }\r
 \r
-                                                       ReInPass = NO;\r
-                                                       do\r
-                                                       {\r
-                                                               Continue = NO;\r
-                                                               if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
+                                                               ReInPass = NO;\r
+                                                               do\r
                                                                {\r
-                                                                       if((strlen(Pass) != 0) || \r
-                                                                          (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                       // FTPES対応\r
+                                                                       if(Sts == FTP_ERROR)\r
+                                                                               break;\r
+                                                                       Continue = NO;\r
+                                                                       if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
                                                                        {\r
-                                                                               CheckOneTimePassword(Pass, Reply, Security);\r
+                                                                               if((strlen(Pass) != 0) || \r
+                                                                                  (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                               {\r
+                                                                                       CheckOneTimePassword(Pass, Reply, Security);\r
 \r
-                                                                               /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
-                                                                               if(strcmp(Reply, " ") == 0)\r
-                                                                                       strcpy(Reply, "");\r
+                                                                                       /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
+                                                                                       if(strcmp(Reply, " ") == 0)\r
+                                                                                               strcpy(Reply, "");\r
 \r
-                                                                               Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
-                                                                               if(Sts == FTP_ERROR)\r
-                                                                               {\r
-                                                                                       strcpy(Pass, "");\r
-                                                                                       if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
-                                                                                               Continue = YES;\r
-                                                                                       else\r
-                                                                                               DoPrintf("No password specified.");\r
-                                                                                       ReInPass = YES;\r
-                                                                               }\r
-                                                                               else if(Sts == FTP_CONTINUE)\r
-                                                                               {\r
-                                                                                       if((strlen(Acct) != 0) || \r
-                                                                                          (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                                       Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
+                                                                                       if(Sts == FTP_ERROR)\r
                                                                                        {\r
-                                                                                               Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
+                                                                                               strcpy(Pass, "");\r
+                                                                                               if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
+                                                                                                       Continue = YES;\r
+                                                                                               else\r
+                                                                                                       DoPrintf("No password specified.");\r
+                                                                                               ReInPass = YES;\r
+                                                                                       }\r
+                                                                                       else if(Sts == FTP_CONTINUE)\r
+                                                                                       {\r
+                                                                                               if((strlen(Acct) != 0) || \r
+                                                                                                  (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
+                                                                                               {\r
+                                                                                                       Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
+                                                                                               }\r
+                                                                                               else\r
+                                                                                                       DoPrintf("No account specified");\r
                                                                                        }\r
-                                                                                       else\r
-                                                                                               DoPrintf("No account specified");\r
                                                                                }\r
-                                                                       }\r
-                                                                       else\r
-                                                                       {\r
-                                                                               Sts = FTP_ERROR;\r
-                                                                               DoPrintf("No password specified.");\r
+                                                                               else\r
+                                                                               {\r
+                                                                                       Sts = FTP_ERROR;\r
+                                                                                       DoPrintf("No password specified.");\r
+                                                                               }\r
                                                                        }\r
                                                                }\r
+                                                               while(Continue == YES);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               Sts = FTP_ERROR;\r
+                                                               DoPrintf("No user name specified");\r
                                                        }\r
-                                                       while(Continue == YES);\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       Sts = FTP_ERROR;\r
-                                                       DoPrintf("No user name specified");\r
-                                               }\r
 \r
-                                               if(Sts != FTP_COMPLETE)\r
-                                               {\r
-                                                       SetTaskMsg(MSGJPN008, Host);\r
-                                                       DoClose(ContSock);\r
-                                                       ContSock = INVALID_SOCKET;\r
-                                               }\r
-                                               else if((SavePass == YES) && (ReInPass == YES))\r
-                                               {\r
-                                                       if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
-                                                               SetHostPassword(AskCurrentHost(), Pass);\r
+                                                       if(Sts != FTP_COMPLETE)\r
+                                                       {\r
+                                                               SetTaskMsg(MSGJPN008, Host);\r
+                                                               DoClose(ContSock);\r
+                                                               ContSock = INVALID_SOCKET;\r
+                                                       }\r
+                                                       else if((SavePass == YES) && (ReInPass == YES))\r
+                                                       {\r
+                                                               if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
+                                                                       SetHostPassword(AskCurrentHost(), Pass);\r
+                                                       }\r
                                                }\r
                                        }\r
                                }\r
+                               else\r
+                               {\r
+//#pragma aaa\r
+                                       SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
+                                       DoClose(ContSock);\r
+                                       ContSock = INVALID_SOCKET;\r
+                               }\r
                        }\r
+               }\r
+               else\r
+               {\r
+\r
+                       if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
+                          (Fwall == FWALL_FU_FP))\r
+                               SetTaskMsg(MSGJPN010);\r
                        else\r
+                               SetTaskMsg(MSGJPN011);\r
+               }\r
+\r
+#if 0\r
+//             WSAUnhookBlockingHook();\r
+#endif\r
+               TryConnect = NO;\r
+\r
+               // FEAT対応\r
+               // ホストの機能を確認\r
+               if(ContSock != INVALID_SOCKET)\r
+               {\r
+                       if((Sts = command(ContSock, Reply, &CancelFlg, "FEAT")) == 211)\r
                        {\r
-//#pragma aaa\r
-                               SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
-                               DoClose(ContSock);\r
-                               ContSock = INVALID_SOCKET;\r
+                               // 改行文字はReadReplyMessageで消去されるため区切り文字に空白を使用\r
+                               // UTF-8対応\r
+                               if(strstr(Reply, " UTF8 "))\r
+                                       HostData->Feature |= FEATURE_UTF8;\r
+                               // 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
+                       {\r
+                               if((Sts = command(ContSock, Reply, &CancelFlg, "OPTS UTF8 ON")) == 200)\r
+                               {\r
+                               }\r
                        }\r
                }\r
        }\r
-       else\r
+       else if(CryptMode == CRYPT_SFTP)\r
        {\r
-\r
-               if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
-                  (Fwall == FWALL_FU_FP))\r
-                       SetTaskMsg(MSGJPN010);\r
-               else\r
-                       SetTaskMsg(MSGJPN011);\r
        }\r
 \r
-#if 0\r
-//     WSAUnhookBlockingHook();\r
-#endif\r
-       TryConnect = NO;\r
-\r
        return(ContSock);\r
 }\r
 \r
+static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
+{\r
+       SOCKET ContSock;\r
+       ContSock = INVALID_SOCKET;\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(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(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
+                       HostData->CryptMode = CRYPT_NONE;\r
+       }\r
+       return ContSock;\r
+}\r
+\r
 \r
 /*----- ワンタイムパスワードのチェック ----------------------------------------\r
 *\r
@@ -2175,6 +2315,11 @@ int AskCryptMode(void)
        return(CurHost.CryptMode);\r
 }\r
 \r
+int AskUseNoEncryption(void)\r
+{\r
+       return(CurHost.UseNoEncryption);\r
+}\r
+\r
 int AskUseFTPES(void)\r
 {\r
        return(CurHost.UseFTPES);\r
@@ -2190,3 +2335,32 @@ 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
+       return(CurHost.MaxThreadCount);\r
+}\r
+\r
+// FEAT対応\r
+int AskHostFeature(void)\r
+{\r
+       return(CurHost.Feature);\r
+}\r
+\r
+// MLSD対応\r
+int AskUseMLSD(void)\r
+{\r
+       return(CurHost.UseMLSD);\r
+}\r
+\r
+// IPv6対応\r
+int AskUseIPv6(void)\r
+{\r
+       return(CurHost.UseIPv6);\r
+}\r
+\r