OSDN Git Service

Add support for MLSD responses from some broken hosts.
[ffftp/ffftp.git] / getput.c
index 9573c3e..28c2471 100644 (file)
--- a/getput.c
+++ b/getput.c
@@ -41,7 +41,9 @@
 #include <string.h>\r
 #include <mbstring.h>\r
 #include <time.h>\r
-#include <winsock.h>\r
+// IPv6対応\r
+//#include <winsock.h>\r
+#include <winsock2.h>\r
 #include <windowsx.h>\r
 #include <commctrl.h>\r
 #include <process.h>\r
@@ -86,29 +88,47 @@ static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork);
 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork);\r
 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork);\r
 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
-static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname);\r
-static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+// 再転送対応\r
+//static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname);\r
+static int DispUpDownErrDialog(int ResID, HWND hWnd, TRANSPACKET *Pkt);\r
+// 64ビット対応\r
+//static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+static INT_PTR CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork);\r
-static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+// 64ビット対応\r
+//static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+static INT_PTR CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt);\r
 static int UpLoadNonPassive(TRANSPACKET *Pkt);\r
 static int UpLoadPassive(TRANSPACKET *Pkt);\r
 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt);\r
-static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii);\r
+// 同時接続対応\r
+//static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii);\r
+static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii, int *CancelCheckWork);\r
 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
 static int SetUploadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode);\r
 static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);\r
 static void DispTransferStatus(HWND hWnd, int End, TRANSPACKET *Pkt);\r
 static void DispTransFileInfo(TRANSPACKET *Pkt, char *Title, int SkipButton, int Info);\r
-static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max);\r
+// IPv6対応\r
+//static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max);\r
+static int GetAdrsAndPort(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
+static int GetAdrsAndPortIPv4(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
+static int GetAdrsAndPortIPv6(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
 static int IsSpecialDevice(char *Fname);\r
 static int MirrorDelNotify(int Cur, int Notify, TRANSPACKET *Pkt);\r
-static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+// 64ビット対応\r
+//static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
+static INT_PTR CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
 static void SetErrorMsg(char *fmt, ...);\r
+// 同時接続対応\r
+static char* GetErrMsg();\r
 \r
 /*===== ローカルなワーク =====*/\r
 \r
-static HANDLE hTransferThread;\r
+// 同時接続対応\r
+//static HANDLE hTransferThread;\r
+static HANDLE hTransferThread[MAX_DATA_CONNECTION];\r
 static int fTransferThreadExit = FALSE;\r
 \r
 static HANDLE hRunMutex;                               /* 転送スレッド実行ミューテックス */\r
@@ -116,21 +136,40 @@ static HANDLE hListAccMutex;                      /* 転送ファイルアクセス用ミューテ
 \r
 static int TransFiles = 0;                             /* 転送待ちファイル数 */\r
 static TRANSPACKET *TransPacketBase = NULL;    /* 転送ファイルリスト */\r
+// 同時接続対応\r
+static TRANSPACKET *NextTransPacketBase = NULL;\r
 \r
-static int Canceled;           /* 中止フラグ YES/NO */\r
+// 同時接続対応\r
+//static int Canceled;         /* 中止フラグ YES/NO */\r
+static int Canceled[MAX_DATA_CONNECTION];              /* 中止フラグ YES/NO */\r
 static int ClearAll;           /* 全て中止フラグ YES/NO */\r
 \r
 static int ForceAbort;         /* 転送中止フラグ */\r
                                                        /* このフラグはスレッドを終了させるときに使う */\r
 \r
-static LONGLONG AllTransSizeNow;       /* 今回の転送で転送したサイズ */\r
-static time_t TimeStart;       /* 転送開始時間 */\r
+// 同時接続対応\r
+//static LONGLONG AllTransSizeNow;     /* 今回の転送で転送したサイズ */\r
+//static time_t TimeStart;     /* 転送開始時間 */\r
+static LONGLONG AllTransSizeNow[MAX_DATA_CONNECTION];  /* 今回の転送で転送したサイズ */\r
+static time_t TimeStart[MAX_DATA_CONNECTION];  /* 転送開始時間 */\r
 \r
 static int KeepDlg = NO;       /* 転送中ダイアログを消さないかどうか (YES/NO) */\r
 static int MoveToForeground = NO;              /* ウインドウを前面に移動するかどうか (YES/NO) */\r
 \r
-static char CurDir[FMAX_PATH+1] = { "" };\r
-static char ErrMsg[ERR_MSG_LEN+7];\r
+// 同時接続対応\r
+//static char CurDir[FMAX_PATH+1] = { "" };\r
+static char CurDir[MAX_DATA_CONNECTION][FMAX_PATH+1];\r
+// 同時接続対応\r
+//static char ErrMsg[ERR_MSG_LEN+7];\r
+static char ErrMsg[MAX_DATA_CONNECTION+1][ERR_MSG_LEN+7];\r
+static DWORD ErrMsgThreadId[MAX_DATA_CONNECTION+1];\r
+static HANDLE hErrMsgMutex;\r
+\r
+// 同時接続対応\r
+static int WaitForMainThread = NO;\r
+// 再転送対応\r
+static int TransferErrorMode = EXIST_OVW;\r
+static int TransferErrorNotify = NO;\r
 \r
 /*===== 外部参照 =====*/\r
 \r
@@ -157,17 +196,27 @@ extern int FolderAttrNum;
 int MakeTransferThread(void)\r
 {\r
        DWORD dwID;\r
+       int i;\r
 \r
        hListAccMutex = CreateMutex( NULL, FALSE, NULL );\r
        hRunMutex = CreateMutex( NULL, TRUE, NULL );\r
+       // 同時接続対応\r
+       hErrMsgMutex = CreateMutex( NULL, FALSE, NULL );\r
 \r
        ClearAll = NO;\r
        ForceAbort = NO;\r
 \r
        fTransferThreadExit = FALSE;\r
-       hTransferThread = (HANDLE)_beginthreadex(NULL, 0, TransferThread, 0, 0, &dwID);\r
-       if (hTransferThread == NULL)\r
-               return(FFFTP_FAIL); /* XXX */\r
+       // 同時接続対応\r
+//     hTransferThread = (HANDLE)_beginthreadex(NULL, 0, TransferThread, 0, 0, &dwID);\r
+//     if (hTransferThread == NULL)\r
+//             return(FFFTP_FAIL); /* XXX */\r
+       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
+       {\r
+               hTransferThread[i] = (HANDLE)_beginthreadex(NULL, 0, TransferThread, (void*)i, 0, &dwID);\r
+               if(hTransferThread[i] == NULL)\r
+                       return FFFTP_FAIL;\r
+       }\r
 \r
        return(FFFTP_SUCCESS);\r
 }\r
@@ -184,22 +233,38 @@ int MakeTransferThread(void)
 \r
 void CloseTransferThread(void)\r
 {\r
-       Canceled = YES;\r
+       int i;\r
+       // 同時接続対応\r
+//     Canceled = YES;\r
+       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
+               Canceled[i] = YES;\r
        ClearAll = YES;\r
        ForceAbort = YES;\r
 \r
        fTransferThreadExit = TRUE;\r
-       while(WaitForSingleObject(hTransferThread, 10) == WAIT_TIMEOUT)\r
+       // 同時接続対応\r
+//     while(WaitForSingleObject(hTransferThread, 10) == WAIT_TIMEOUT)\r
+//     {\r
+//             BackgrndMessageProc();\r
+//             Canceled = YES;\r
+//     }\r
+//     CloseHandle(hTransferThread);\r
+       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
        {\r
-               BackgrndMessageProc();\r
-               Canceled = YES;\r
+               while(WaitForSingleObject(hTransferThread[i], 10) == WAIT_TIMEOUT)\r
+               {\r
+                       BackgrndMessageProc();\r
+                       Canceled[i] = YES;\r
+               }\r
+               CloseHandle(hTransferThread[i]);\r
        }\r
-       CloseHandle(hTransferThread);\r
 \r
        ReleaseMutex( hRunMutex );\r
 \r
        CloseHandle( hListAccMutex );\r
        CloseHandle( hRunMutex );\r
+       // 同時接続対応\r
+       CloseHandle( hErrMsgMutex );\r
        return;\r
 }\r
 \r
@@ -323,10 +388,27 @@ int RemoveTmpTransFileListItem(TRANSPACKET **Base, int Num)
 \r
 void AddTransFileList(TRANSPACKET *Pkt)\r
 {\r
+       // 同時接続対応\r
+       TRANSPACKET *Pos;\r
+\r
        DispTransPacket(Pkt);\r
 \r
-       WaitForSingleObject(hListAccMutex, INFINITE);\r
+       // 同時接続対応\r
+//     WaitForSingleObject(hListAccMutex, INFINITE);\r
+       while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+       {\r
+               WaitForMainThread = YES;\r
+               BackgrndMessageProc();\r
+               Sleep(1);\r
+       }\r
 \r
+       // 同時接続対応\r
+       Pos = TransPacketBase;\r
+       if(Pos != NULL)\r
+       {\r
+               while(Pos->Next != NULL)\r
+                       Pos = Pos->Next;\r
+       }\r
        if(AddTmpTransFileList(Pkt, &TransPacketBase) == FFFTP_SUCCESS)\r
        {\r
                if((strncmp(Pkt->Cmd, "RETR", 4) == 0) ||\r
@@ -336,7 +418,17 @@ void AddTransFileList(TRANSPACKET *Pkt)
                        PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
                }\r
        }\r
+       // 同時接続対応\r
+       if(NextTransPacketBase == NULL)\r
+       {\r
+               if(Pos)\r
+                       NextTransPacketBase = Pos->Next;\r
+               else\r
+                       NextTransPacketBase = TransPacketBase;\r
+       }\r
        ReleaseMutex(hListAccMutex);\r
+       // 同時接続対応\r
+       WaitForMainThread = NO;\r
 \r
        return;\r
 }\r
@@ -359,7 +451,14 @@ void AppendTransFileList(TRANSPACKET *Pkt)
 {\r
        TRANSPACKET *Pos;\r
 \r
-       WaitForSingleObject(hListAccMutex, INFINITE);\r
+       // 同時接続対応\r
+//     WaitForSingleObject(hListAccMutex, INFINITE);\r
+       while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+       {\r
+               WaitForMainThread = YES;\r
+               BackgrndMessageProc();\r
+               Sleep(1);\r
+       }\r
 \r
        if(TransPacketBase == NULL)\r
                TransPacketBase = Pkt;\r
@@ -370,6 +469,9 @@ void AppendTransFileList(TRANSPACKET *Pkt)
                        Pos = Pos->Next;\r
                Pos->Next = Pkt;\r
        }\r
+       // 同時接続対応\r
+       if(NextTransPacketBase == NULL)\r
+               NextTransPacketBase = Pkt;\r
 \r
        while(Pkt != NULL)\r
        {\r
@@ -385,6 +487,8 @@ void AppendTransFileList(TRANSPACKET *Pkt)
        }\r
 \r
        ReleaseMutex(hListAccMutex);\r
+       // 同時接続対応\r
+       WaitForMainThread = NO;\r
        return;\r
 }\r
 \r
@@ -437,7 +541,14 @@ static void EraseTransFileList(void)
 \r
        NotDel = NULL;\r
 \r
-       WaitForSingleObject(hListAccMutex, INFINITE);\r
+       // 同時接続対応\r
+//     WaitForSingleObject(hListAccMutex, INFINITE);\r
+       while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+       {\r
+               WaitForMainThread = YES;\r
+               BackgrndMessageProc();\r
+               Sleep(1);\r
+       }\r
        New = TransPacketBase;\r
        while(New != NULL)\r
        {\r
@@ -445,22 +556,31 @@ static void EraseTransFileList(void)
                if(strcmp(New->Cmd, "BACKCUR") == 0)\r
                {\r
                        if(NotDel != NULL)\r
-                               free(NotDel);\r
+                               // 同時接続対応\r
+//                             free(NotDel);\r
+                               strcpy(NotDel->Cmd, "");\r
                        NotDel = New;\r
                        New = New->Next;\r
-                       NotDel->Next = NULL;\r
+                       // 同時接続対応\r
+//                     NotDel->Next = NULL;\r
                }\r
                else\r
                {\r
                        Next = New->Next;\r
-                       free(New);\r
+                       // 同時接続対応\r
+//                     free(New);\r
+                       strcpy(New->Cmd, "");\r
                        New = Next;\r
                }\r
        }\r
        TransPacketBase = NotDel;\r
+       // 同時接続対応\r
+       NextTransPacketBase = NotDel;\r
        TransFiles = 0;\r
        PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
        ReleaseMutex(hListAccMutex);\r
+       // 同時接続対応\r
+       WaitForMainThread = NO;\r
 \r
        strcpy(Pkt.Cmd, "GOQUIT");\r
        AddTransFileList(&Pkt);\r
@@ -541,7 +661,11 @@ void GoForwardTransWindow(void)
 \r
 void InitTransCurDir(void)\r
 {\r
-       strcpy(CurDir, "");\r
+       // 同時接続対応\r
+//     strcpy(CurDir, "");\r
+       int i;\r
+       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
+               strcpy(CurDir[i], "");\r
        return;\r
 }\r
 \r
@@ -562,15 +686,31 @@ static ULONG WINAPI TransferThread(void *Dummy)
        char Tmp[FMAX_PATH+1];\r
        int CwdSts;\r
        int GoExit;\r
-       int Down;\r
-       int Up;\r
+//     int Down;\r
+//     int Up;\r
+       static int Down;\r
+       static int Up;\r
        int DelNotify;\r
+       int ThreadCount;\r
+       SOCKET CmdSkt;\r
+       SOCKET NewCmdSkt;\r
+       SOCKET TrnSkt;\r
+       RECT WndRect;\r
+       int i;\r
+       DWORD LastUsed;\r
 \r
        hWndTrans = NULL;\r
        Down = NO;\r
        Up = NO;\r
        GoExit = NO;\r
        DelNotify = NO;\r
+       // 同時接続対応\r
+       // ソケットは各転送スレッドが管理\r
+       ThreadCount = (int)Dummy;\r
+       CmdSkt = INVALID_SOCKET;\r
+       NewCmdSkt = INVALID_SOCKET;\r
+       TrnSkt = INVALID_SOCKET;\r
+       SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);\r
 \r
        while((TransPacketBase != NULL) ||\r
                  (WaitForSingleObject(hRunMutex, 200) == WAIT_TIMEOUT))\r
@@ -578,29 +718,130 @@ static ULONG WINAPI TransferThread(void *Dummy)
                if(fTransferThreadExit == TRUE)\r
                        break;\r
 \r
-               WaitForSingleObject(hListAccMutex, INFINITE);\r
-               memset(ErrMsg, NUL, ERR_MSG_LEN+7);\r
+               if(WaitForMainThread == YES)\r
+               {\r
+                       BackgrndMessageProc();\r
+                       Sleep(100);\r
+                       continue;\r
+               }\r
+\r
+//             WaitForSingleObject(hListAccMutex, INFINITE);\r
+               while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+               {\r
+                       BackgrndMessageProc();\r
+                       Sleep(1);\r
+               }\r
+//             memset(ErrMsg, NUL, ERR_MSG_LEN+7);\r
+               memset(GetErrMsg(), NUL, ERR_MSG_LEN+7);\r
 \r
-               Canceled = NO;\r
+//             Canceled = NO;\r
+               Canceled[ThreadCount] = NO;\r
 \r
-               if(TransPacketBase != NULL)\r
+               while(TransPacketBase != NULL && strcmp(TransPacketBase->Cmd, "") == 0)\r
                {\r
-                       ReleaseMutex(hListAccMutex);\r
+                       Pos = TransPacketBase;\r
+                       TransPacketBase = TransPacketBase->Next;\r
+                       free(Pos);\r
+               }\r
+               NewCmdSkt = AskCmdCtrlSkt();\r
+               if(AskReuseCmdSkt() == YES && ThreadCount == 0)\r
+               {\r
+                       if(TransPacketBase && ThreadCount < AskMaxThreadCount())\r
+                               TrnSkt = AskTrnCtrlSkt();\r
+               }\r
+               else\r
+               {\r
+                       if(TransPacketBase && NewCmdSkt != INVALID_SOCKET && ThreadCount < AskMaxThreadCount())\r
+                       {\r
+                               if(TrnSkt == INVALID_SOCKET || NewCmdSkt != CmdSkt)\r
+                               {\r
+                                       ReleaseMutex(hListAccMutex);\r
+                                       ReConnectTrnSkt(&TrnSkt, &Canceled[ThreadCount]);\r
+                                       // 同時ログイン数制限対策\r
+                                       if(TrnSkt != INVALID_SOCKET)\r
+                                               LastUsed = timeGetTime();\r
+                                       else\r
+                                       {\r
+                                               // 同時ログイン数制限に引っかかった可能性あり\r
+                                               // 負荷を下げるために約10秒間待機\r
+                                               i = 10000;\r
+                                               while(NewCmdSkt != CmdSkt && i > 0)\r
+                                               {\r
+                                                       BackgrndMessageProc();\r
+                                                       Sleep(1);\r
+                                                       i--;\r
+                                               }\r
+                                       }\r
+//                                     WaitForSingleObject(hListAccMutex, INFINITE);\r
+                                       while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+                                       {\r
+                                               BackgrndMessageProc();\r
+                                               Sleep(1);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if(TrnSkt != INVALID_SOCKET)\r
+                               {\r
+                                       // 同時ログイン数制限対策\r
+                                       // 10秒間は再利用を許可\r
+                                       if(timeGetTime() - LastUsed > 10000)\r
+                                       {\r
+                                               ReleaseMutex(hListAccMutex);\r
+                                               SendData(TrnSkt, "QUIT\r\n", 6, 0, &Canceled[ThreadCount]);\r
+                                               DoClose(TrnSkt);\r
+                                               TrnSkt = INVALID_SOCKET;\r
+//                                             WaitForSingleObject(hListAccMutex, INFINITE);\r
+                                               while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+                                               {\r
+                                                       BackgrndMessageProc();\r
+                                                       Sleep(1);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               CmdSkt = NewCmdSkt;\r
+//             if(TransPacketBase != NULL)\r
+               if(TrnSkt != INVALID_SOCKET && NextTransPacketBase != NULL)\r
+               {\r
+                       if(strcmp(NextTransPacketBase->Cmd, "GOQUIT") == 0 && NextTransPacketBase != TransPacketBase)\r
+                       {\r
+                               ReleaseMutex(hListAccMutex);\r
+                               BackgrndMessageProc();\r
+                               Sleep(1);\r
+                               continue;\r
+                       }\r
+                       Pos = NextTransPacketBase;\r
+                       NextTransPacketBase = NextTransPacketBase->Next;\r
+                       // ディレクトリ操作は非同期で行わない\r
+//                     ReleaseMutex(hListAccMutex);\r
                        if(hWndTrans == NULL)\r
                        {\r
-                               if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
-                                  (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0) ||\r
-                                  (strncmp(TransPacketBase->Cmd, "MKD", 3) == 0) ||\r
-                                  (strncmp(TransPacketBase->Cmd, "L-", 2) == 0) ||\r
-                                  (strncmp(TransPacketBase->Cmd, "R-", 2) == 0))\r
+//                             if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
+//                                (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0) ||\r
+//                                (strncmp(TransPacketBase->Cmd, "MKD", 3) == 0) ||\r
+//                                (strncmp(TransPacketBase->Cmd, "L-", 2) == 0) ||\r
+//                                (strncmp(TransPacketBase->Cmd, "R-", 2) == 0))\r
+                               if((strncmp(Pos->Cmd, "RETR", 4) == 0) ||\r
+                                  (strncmp(Pos->Cmd, "STOR", 4) == 0) ||\r
+                                  (strncmp(Pos->Cmd, "MKD", 3) == 0) ||\r
+                                  (strncmp(Pos->Cmd, "L-", 2) == 0) ||\r
+                                  (strncmp(Pos->Cmd, "R-", 2) == 0))\r
                                {\r
                                        hWndTrans = CreateDialog(GetFtpInst(), MAKEINTRESOURCE(transfer_dlg), HWND_DESKTOP, (DLGPROC)TransDlgProc);\r
                                        if(MoveToForeground == YES)\r
                                                SetForegroundWindow(hWndTrans);\r
                                        ShowWindow(hWndTrans, SW_SHOWNOACTIVATE);\r
+                                       GetWindowRect(hWndTrans, &WndRect);\r
+                                       SetWindowPos(hWndTrans, NULL, WndRect.left, WndRect.top + (WndRect.bottom - WndRect.top) * ThreadCount - (WndRect.bottom - WndRect.top) * (AskMaxThreadCount() - 1) / 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER);\r
                                }\r
                        }\r
-                       TransPacketBase->hWndTrans = hWndTrans;\r
+//                     TransPacketBase->hWndTrans = hWndTrans;\r
+                       Pos->hWndTrans = hWndTrans;\r
+                       Pos->ctrl_skt = TrnSkt;\r
+                       Pos->ThreadCount = ThreadCount;\r
 \r
                        if(hWndTrans != NULL)\r
                        {\r
@@ -612,60 +853,85 @@ static ULONG WINAPI TransferThread(void *Dummy)
                        }\r
 \r
                        if(hWndTrans != NULL)\r
-                               SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)TransPacketBase);\r
+//                             SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)TransPacketBase);\r
+                               SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)Pos);\r
 \r
                        /* ダウンロード */\r
-                       if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
+//                     if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
+                       if(strncmp(Pos->Cmd, "RETR", 4) == 0)\r
                        {\r
+                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+//                             ReleaseMutex(hListAccMutex);\r
                                /* 不正なパスを検出 */\r
-                               if(CheckPathViolation(TransPacketBase) == NO)\r
+//                             if(CheckPathViolation(TransPacketBase) == NO)\r
+                               if(CheckPathViolation(Pos) == NO)\r
                                {\r
                                        /* フルパスを使わないための処理 */\r
-                                       if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+//                                     if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+                                       if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
                                        {\r
-                                               if(strncmp(TransPacketBase->Cmd, "RETR-S", 6) == 0)\r
+//                                             if(strncmp(TransPacketBase->Cmd, "RETR-S", 6) == 0)\r
+                                               if(strncmp(Pos->Cmd, "RETR-S", 6) == 0)\r
                                                {\r
                                                        /* サイズと日付を取得 */\r
-                                                       DoSIZE(TransPacketBase->RemoteFile, &TransPacketBase->Size);\r
-                                                       DoMDTM(TransPacketBase->RemoteFile, &TransPacketBase->Time);\r
-                                                       strcpy(TransPacketBase->Cmd, "RETR ");\r
+//                                                     DoSIZE(TransPacketBase->RemoteFile, &TransPacketBase->Size);\r
+//                                                     DoMDTM(TransPacketBase->RemoteFile, &TransPacketBase->Time);\r
+//                                                     strcpy(TransPacketBase->Cmd, "RETR ");\r
+                                                       DoSIZE(TrnSkt, Pos->RemoteFile, &Pos->Size, &Canceled[Pos->ThreadCount]);\r
+                                                       DoMDTM(TrnSkt, Pos->RemoteFile, &Pos->Time, &Canceled[Pos->ThreadCount]);\r
+                                                       strcpy(Pos->Cmd, "RETR ");\r
                                                }\r
 \r
                                                Down = YES;\r
 //                                             if(DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO) == 429)\r
 //                                             {\r
 //                                                     if(ReConnectTrnSkt() == FFFTP_SUCCESS)\r
-                                                               DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO, &Canceled);\r
+//                                                             DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO, &Canceled);\r
+                                                               DoDownLoad(TrnSkt, Pos, NO, &Canceled[Pos->ThreadCount]);\r
 //                                             }\r
                                        }\r
                                }\r
+                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* アップロード */\r
-                       else if(strncmp(TransPacketBase->Cmd, "STOR", 4) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "STOR", 4) == 0)\r
+                       else if(strncmp(Pos->Cmd, "STOR", 4) == 0)\r
                        {\r
+                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+//                             ReleaseMutex(hListAccMutex);\r
                                /* フルパスを使わないための処理 */\r
-                               if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+//                             if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+                               if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
                                {\r
                                        Up = YES;\r
 //                                     if(DoUpLoad(AskTrnCtrlSkt(), TransPacketBase) == 429)\r
 //                                     {\r
 //                                             if(ReConnectTrnSkt() == FFFTP_SUCCESS)\r
-                                                       DoUpLoad(AskTrnCtrlSkt(), TransPacketBase);\r
+//                                                     DoUpLoad(AskTrnCtrlSkt(), TransPacketBase);\r
+                                                       DoUpLoad(TrnSkt, Pos);\r
 //                                     }\r
                                }\r
+                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* フォルダ作成(ローカルまたはホスト) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "MKD", 3) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "MKD", 3) == 0)\r
+                       else if(strncmp(Pos->Cmd, "MKD", 3) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN078, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN078, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN078, FALSE, YES);\r
 \r
-                               if(strlen(TransPacketBase->RemoteFile) > 0)\r
+//                             if(strlen(TransPacketBase->RemoteFile) > 0)\r
+                               if(strlen(Pos->RemoteFile) > 0)\r
                                {\r
                                        /* フルパスを使わないための処理 */\r
                                        CwdSts = FTP_COMPLETE;\r
 \r
-                                       strcpy(Tmp, TransPacketBase->RemoteFile);\r
-                                       if(ProcForNonFullpath(Tmp, CurDir, hWndTrans, 1) == FFFTP_FAIL)\r
+//                                     strcpy(Tmp, TransPacketBase->RemoteFile);\r
+                                       strcpy(Tmp, Pos->RemoteFile);\r
+//                                     if(ProcForNonFullpath(Tmp, CurDir, hWndTrans, 1) == FFFTP_FAIL)\r
+                                       if(ProcForNonFullpath(TrnSkt, Tmp, CurDir[Pos->ThreadCount], hWndTrans, &Canceled[Pos->ThreadCount]) == FFFTP_FAIL)\r
                                        {\r
                                                ClearAll = YES;\r
                                                CwdSts = FTP_ERROR;\r
@@ -674,149 +940,217 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                        if(CwdSts == FTP_COMPLETE)\r
                                        {\r
                                                Up = YES;\r
-                                               CommandProcTrn(NULL, "MKD %s", Tmp);\r
+//                                             CommandProcTrn(NULL, "MKD %s", Tmp);\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "MKD %s", Tmp);\r
                                                /* すでにフォルダがある場合もあるので、 */\r
                                                /* ここではエラーチェックはしない */\r
 \r
                                        if(FolderAttr)\r
-                                               CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
+//                                             CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
                                        }\r
                                }\r
-                               else if(strlen(TransPacketBase->LocalFile) > 0)\r
+//                             else if(strlen(TransPacketBase->LocalFile) > 0)\r
+                               else if(strlen(Pos->LocalFile) > 0)\r
                                {\r
                                        Down = YES;\r
-                                       DoLocalMKD(TransPacketBase->LocalFile);\r
+//                                     DoLocalMKD(TransPacketBase->LocalFile);\r
+                                       DoLocalMKD(Pos->LocalFile);\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ディレクトリ作成(常にホスト側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "R-MKD", 5) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "R-MKD", 5) == 0)\r
+                       else if(strncmp(Pos->Cmd, "R-MKD", 5) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN079, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN079, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN079, FALSE, YES);\r
 \r
                                /* フルパスを使わないための処理 */\r
-                               if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+//                             if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+                               if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
                                {\r
                                        Up = YES;\r
-                                       CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+//                                     CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+                                       CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
 \r
                                        if(FolderAttr)\r
-                                               CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, TransPacketBase->RemoteFile);\r
+//                                             CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, TransPacketBase->RemoteFile);\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Pos->RemoteFile);\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ディレクトリ削除(常にホスト側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "R-RMD", 5) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "R-RMD", 5) == 0)\r
+                       else if(strncmp(Pos->Cmd, "R-RMD", 5) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN080, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN080, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN080, FALSE, YES);\r
 \r
-                               DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
+//                             DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
+                               DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, Pos);\r
                                if((DelNotify == YES) || (DelNotify == YES_ALL))\r
                                {\r
                                        /* フルパスを使わないための処理 */\r
-                                       if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+//                                     if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+                                       if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
                                        {\r
                                                Up = YES;\r
-                                               CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+//                                             CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
                                        }\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ファイル削除(常にホスト側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "R-DELE", 6) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "R-DELE", 6) == 0)\r
+                       else if(strncmp(Pos->Cmd, "R-DELE", 6) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN081, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN081, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN081, FALSE, YES);\r
 \r
-                               DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
+//                             DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
+                               DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, Pos);\r
                                if((DelNotify == YES) || (DelNotify == YES_ALL))\r
                                {\r
                                        /* フルパスを使わないための処理 */\r
-                                       if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+//                                     if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
+                                       if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
                                        {\r
                                                Up = YES;\r
-                                               CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+//                                             CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
                                        }\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ディレクトリ作成(常にローカル側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "L-MKD", 5) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "L-MKD", 5) == 0)\r
+                       else if(strncmp(Pos->Cmd, "L-MKD", 5) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN082, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN082, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN082, FALSE, YES);\r
 \r
                                Down = YES;\r
-                               DoLocalMKD(TransPacketBase->LocalFile);\r
+//                             DoLocalMKD(TransPacketBase->LocalFile);\r
+                               DoLocalMKD(Pos->LocalFile);\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ディレクトリ削除(常にローカル側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "L-RMD", 5) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "L-RMD", 5) == 0)\r
+                       else if(strncmp(Pos->Cmd, "L-RMD", 5) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN083, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN083, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN083, FALSE, YES);\r
 \r
-                               DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
+//                             DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
+                               DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, Pos);\r
                                if((DelNotify == YES) || (DelNotify == YES_ALL))\r
                                {\r
                                        Down = YES;\r
-                                       DoLocalRMD(TransPacketBase->LocalFile);\r
+//                                     DoLocalRMD(TransPacketBase->LocalFile);\r
+                                       DoLocalRMD(Pos->LocalFile);\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* ファイル削除(常にローカル側) */\r
-                       else if(strncmp(TransPacketBase->Cmd, "L-DELE", 6) == 0)\r
+//                     else if(strncmp(TransPacketBase->Cmd, "L-DELE", 6) == 0)\r
+                       else if(strncmp(Pos->Cmd, "L-DELE", 6) == 0)\r
                        {\r
-                               DispTransFileInfo(TransPacketBase, MSGJPN084, FALSE, YES);\r
+//                             DispTransFileInfo(TransPacketBase, MSGJPN084, FALSE, YES);\r
+                               DispTransFileInfo(Pos, MSGJPN084, FALSE, YES);\r
 \r
-                               DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
+//                             DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
+                               DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, Pos);\r
                                if((DelNotify == YES) || (DelNotify == YES_ALL))\r
                                {\r
                                        Down = YES;\r
-                                       DoLocalDELE(TransPacketBase->LocalFile);\r
+//                                     DoLocalDELE(TransPacketBase->LocalFile);\r
+                                       DoLocalDELE(Pos->LocalFile);\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* カレントディレクトリを設定 */\r
-                       else if(strcmp(TransPacketBase->Cmd, "SETCUR") == 0)\r
+//                     else if(strcmp(TransPacketBase->Cmd, "SETCUR") == 0)\r
+                       else if(strcmp(Pos->Cmd, "SETCUR") == 0)\r
                        {\r
-                               if(AskShareProh() == YES)\r
+//                             if(AskShareProh() == YES)\r
+                               if(AskReuseCmdSkt() == NO || AskShareProh() == YES)\r
                                {\r
-                                       if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
+//                                     if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
+                                       if(strcmp(CurDir[Pos->ThreadCount], Pos->RemoteFile) != 0)\r
                                        {\r
-                                               if(CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile)/100 != FTP_COMPLETE)\r
+//                                             if(CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile)/100 != FTP_COMPLETE)\r
+                                               if(CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "CWD %s", Pos->RemoteFile)/100 != FTP_COMPLETE)\r
                                                {\r
                                                        DispCWDerror(hWndTrans);\r
                                                        ClearAll = YES;\r
                                                }\r
                                        }\r
                                }\r
-                               strcpy(CurDir, TransPacketBase->RemoteFile);\r
+//                             strcpy(CurDir, TransPacketBase->RemoteFile);\r
+                               strcpy(CurDir[Pos->ThreadCount], Pos->RemoteFile);\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* カレントディレクトリを戻す */\r
-                       else if(strcmp(TransPacketBase->Cmd, "BACKCUR") == 0)\r
+//                     else if(strcmp(TransPacketBase->Cmd, "BACKCUR") == 0)\r
+                       else if(strcmp(Pos->Cmd, "BACKCUR") == 0)\r
                        {\r
-                               if(AskShareProh() == NO)\r
+//                             if(AskShareProh() == NO)\r
+                               if(AskReuseCmdSkt() == YES && AskShareProh() == NO)\r
                                {\r
-                                       if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
-                                               CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile);\r
-                                       strcpy(CurDir, TransPacketBase->RemoteFile);\r
+//                                     if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
+//                                             CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile);\r
+//                                     strcpy(CurDir, TransPacketBase->RemoteFile);\r
+                                       if(strcmp(CurDir[Pos->ThreadCount], Pos->RemoteFile) != 0)\r
+                                               CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "CWD %s", Pos->RemoteFile);\r
+                                       strcpy(CurDir[Pos->ThreadCount], Pos->RemoteFile);\r
                                }\r
+                               ReleaseMutex(hListAccMutex);\r
                        }\r
                        /* 自動終了のための通知 */\r
-                       else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
+//                     else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
+                       else if(strcmp(Pos->Cmd, "GOQUIT") == 0)\r
                        {\r
+                               ReleaseMutex(hListAccMutex);\r
                                GoExit = YES;\r
                        }\r
+                       else\r
+                               ReleaseMutex(hListAccMutex);\r
 \r
                        /*===== 1つの処理終わり =====*/\r
 \r
                        if(ForceAbort == NO)\r
                        {\r
-                               WaitForSingleObject(hListAccMutex, INFINITE);\r
+//                             WaitForSingleObject(hListAccMutex, INFINITE);\r
+                               while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
+                               {\r
+                                       BackgrndMessageProc();\r
+                                       Sleep(1);\r
+                               }\r
                                if(ClearAll == YES)\r
+//                                     EraseTransFileList();\r
+                               {\r
+                                       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
+                                               Canceled[i] = YES;\r
                                        EraseTransFileList();\r
+                                       Pos = NULL;\r
+                               }\r
                                else\r
                                {\r
-                                       if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
-                                          (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0))\r
+//                                     if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
+//                                        (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0))\r
+                                       if((strncmp(Pos->Cmd, "RETR", 4) == 0) ||\r
+                                          (strncmp(Pos->Cmd, "STOR", 4) == 0))\r
                                        {\r
-                                               TransFiles--;\r
+//                                             TransFiles--;\r
+                                               if(TransFiles > 0)\r
+                                                       TransFiles--;\r
                                                PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
                                        }\r
-                                       Pos = TransPacketBase;\r
-                                       TransPacketBase = TransPacketBase->Next;\r
-                                       free(Pos);\r
+//                                     Pos = TransPacketBase;\r
+//                                     TransPacketBase = TransPacketBase->Next;\r
+//                                     free(Pos);\r
                                }\r
                                ClearAll = NO;\r
                                ReleaseMutex(hListAccMutex);\r
@@ -828,8 +1162,14 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                        ReleaseMutex(hListAccMutex);\r
                                }\r
                        }\r
+                       if(hWndTrans != NULL)\r
+                               SendMessage(hWndTrans, WM_SET_PACKET, 0, 0);\r
+                       if(Pos != NULL)\r
+                               strcpy(Pos->Cmd, "");\r
+                       LastUsed = timeGetTime();\r
                }\r
-               else\r
+//             else\r
+               else if(TransPacketBase == NULL)\r
                {\r
                        DelNotify = NO;\r
 \r
@@ -841,29 +1181,67 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                        DestroyWindow(hWndTrans);\r
                                        hWndTrans = NULL;\r
 \r
-                                       if(GoExit == YES)\r
-                                       {\r
-                                               SoundPlay(SND_TRANS);\r
-\r
-                                               if(AskAutoExit() == NO)\r
-                                               {\r
-                                                       if(Down == YES)\r
-                                                               PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
-                                                       if(Up == YES)\r
-                                                               PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
-                                               }\r
-                                               Down = NO;\r
-                                               Up = NO;\r
-                                       }\r
+//                                     if(GoExit == YES)\r
+//                                     {\r
+//                                             SoundPlay(SND_TRANS);\r
+//\r
+//                                             if(AskAutoExit() == NO)\r
+//                                             {\r
+//                                                     if(Down == YES)\r
+//                                                             PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
+//                                                     if(Up == YES)\r
+//                                                             PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
+//                                             }\r
+//                                             Down = NO;\r
+//                                             Up = NO;\r
+//                                     }\r
                                }\r
                        }\r
                        BackgrndMessageProc();\r
+//                     Sleep(1);\r
+                       Sleep(100);\r
 \r
                        if(GoExit == YES)\r
                        {\r
+                               SoundPlay(SND_TRANS);\r
+                               if(AskAutoExit() == NO)\r
+                               {\r
+                                       if(Down == YES)\r
+                                               PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
+                                       if(Up == YES)\r
+                                               PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
+                               }\r
+                               Down = NO;\r
+                               Up = NO;\r
                                PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_AUTO_EXIT, 0), 0);\r
                                GoExit = NO;\r
                        }\r
+\r
+                       // 再転送対応\r
+                       TransferErrorMode = AskTransferErrorMode();\r
+                       TransferErrorNotify = AskTransferErrorNotify();\r
+               }\r
+               else\r
+               {\r
+                       ReleaseMutex(hListAccMutex);\r
+                       if(hWndTrans != NULL)\r
+                       {\r
+                               DestroyWindow(hWndTrans);\r
+                               hWndTrans = NULL;\r
+                       }\r
+                       BackgrndMessageProc();\r
+                       if(ThreadCount < AskMaxThreadCount())\r
+                               Sleep(1);\r
+                       else\r
+                               Sleep(100);\r
+               }\r
+       }\r
+       if(AskReuseCmdSkt() == NO || ThreadCount > 0)\r
+       {\r
+               if(TrnSkt != INVALID_SOCKET)\r
+               {\r
+                       SendData(TrnSkt, "QUIT\r\n", 6, 0, &Canceled[ThreadCount]);\r
+                       DoClose(TrnSkt);\r
                }\r
        }\r
        return 0;\r
@@ -886,11 +1264,13 @@ static ULONG WINAPI TransferThread(void *Dummy)
 *                      Pkt->RemoteFile にファイル名のみ残す。(パス名は消す)\r
 *----------------------------------------------------------------------------*/\r
 \r
+// 同時接続対応\r
 static int MakeNonFullPath(TRANSPACKET *Pkt, char *Cur, char *Tmp)\r
 {\r
        int Sts;\r
 \r
-       Sts = ProcForNonFullpath(Pkt->RemoteFile, Cur, Pkt->hWndTrans, 1);\r
+//     Sts = ProcForNonFullpath(Pkt->RemoteFile, Cur, Pkt->hWndTrans, 1);\r
+       Sts = ProcForNonFullpath(Pkt->ctrl_skt, Pkt->RemoteFile, Cur, Pkt->hWndTrans, &Canceled[Pkt->ThreadCount]);\r
        if(Sts == FFFTP_FAIL)\r
                ClearAll = YES;\r
 \r
@@ -937,7 +1317,9 @@ int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)
                {\r
                        if(Pkt->hWndTrans != NULL)\r
                        {\r
-                               AllTransSizeNow = 0;\r
+                               // 同時接続対応\r
+//                             AllTransSizeNow = 0;\r
+                               AllTransSizeNow[Pkt->ThreadCount] = 0;\r
 \r
                                if(DirList == NO)\r
                                        DispTransFileInfo(Pkt, MSGJPN086, TRUE, YES);\r
@@ -945,7 +1327,13 @@ int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)
                                        DispTransFileInfo(Pkt, MSGJPN087, FALSE, NO);\r
                        }\r
 \r
-                       if(BackgrndMessageProc() == NO)\r
+                       // SFTP対応\r
+//                     if(BackgrndMessageProc() == NO)\r
+                       if(IsSFTPAttached(Pkt->ctrl_skt))\r
+                       {\r
+                               // TODO:\r
+                       }\r
+                       else if(BackgrndMessageProc() == NO)\r
                        {\r
                                if(AskPasvMode() != YES)\r
                                        iRetCode = DownLoadNonPassive(Pkt, CancelCheckWork);\r
@@ -985,7 +1373,10 @@ static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork)
        SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
        char Buf[1024];\r
        int CreateMode;\r
-       struct sockaddr_in saSockAddr1;\r
+       // IPv6対応\r
+//     struct sockaddr_in saSockAddr1;\r
+       struct sockaddr_in saSockAddrIPv4;\r
+       struct sockaddr_in6 saSockAddrIPv6;\r
        char Reply[ERR_MSG_LEN+7];\r
 \r
        if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, CancelCheckWork)) != INVALID_SOCKET)\r
@@ -996,10 +1387,24 @@ static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork)
                        iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
                        if(iRetCode/100 == FTP_PRELIM)\r
                        {\r
-                               if(SocksGet2ndBindReply(listen_socket, &data_socket) == FFFTP_FAIL)\r
+                               // 同時接続対応\r
+//                             if(SocksGet2ndBindReply(listen_socket, &data_socket) == FFFTP_FAIL)\r
+                               if(SocksGet2ndBindReply(listen_socket, &data_socket, CancelCheckWork) == FFFTP_FAIL)\r
                                {\r
-                                       iLength = sizeof(saSockAddr1);\r
-                                       data_socket = do_accept(listen_socket, (struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
+                                       // IPv6対応\r
+//                                     iLength = sizeof(saSockAddr1);\r
+//                                     data_socket = do_accept(listen_socket, (struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
+                                       switch(AskCurNetType())\r
+                                       {\r
+                                       case NTYPE_IPV4:\r
+                                               iLength=sizeof(saSockAddrIPv4);\r
+                                               data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv4, (int *)&iLength);\r
+                                               break;\r
+                                       case NTYPE_IPV6:\r
+                                               iLength=sizeof(saSockAddrIPv6);\r
+                                               data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv6, (int *)&iLength);\r
+                                               break;\r
+                                       }\r
 \r
                                        if(shutdown(listen_socket, 1) != 0)\r
                                                ReportWSError("shutdown listen", WSAGetLastError());\r
@@ -1012,19 +1417,33 @@ static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork)
                                                iRetCode = 500;\r
                                        }\r
                                        else\r
-                                               DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
+                                               // IPv6対応\r
+//                                             DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
+                                       {\r
+                                               switch(AskCurNetType())\r
+                                               {\r
+                                               case NTYPE_IPV4:\r
+                                                       DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddrIPv4.sin_addr), ntohs(saSockAddrIPv4.sin_port));\r
+                                                       break;\r
+                                               case NTYPE_IPV6:\r
+                                                       DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet6_ntoa(saSockAddrIPv6.sin6_addr), ntohs(saSockAddrIPv6.sin6_port));\r
+                                                       break;\r
+                                               }\r
+                                       }\r
                                }\r
 \r
                                if(data_socket != INVALID_SOCKET)\r
                                {\r
+                                       // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                                       ReleaseMutex(hListAccMutex);\r
                                        // FTPS対応\r
 //                                     iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
-                                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
+                                       if(IsSSLAttached(Pkt->ctrl_skt))\r
                                        {\r
-                                               if(AttachSSL(data_socket))\r
+                                               if(AttachSSL(data_socket, Pkt->ctrl_skt, CancelCheckWork))\r
                                                        iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
                                                else\r
-                                                       iRetCode = FTP_ERROR;\r
+                                                       iRetCode = 500;\r
                                        }\r
                                        else\r
                                                iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
@@ -1068,15 +1487,29 @@ static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)
        SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
        char Buf[1024];\r
        int CreateMode;\r
-       char Adrs[20];\r
+       // IPv6対応\r
+//     char Adrs[20];\r
+       char Adrs[40];\r
        int Port;\r
        int Flg;\r
        char Reply[ERR_MSG_LEN+7];\r
 \r
-       iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
+       // IPv6対応\r
+//     iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
+       switch(AskCurNetType())\r
+       {\r
+       case NTYPE_IPV4:\r
+               iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
+               break;\r
+       case NTYPE_IPV6:\r
+               iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "EPSV");\r
+               break;\r
+       }\r
        if(iRetCode/100 == FTP_COMPLETE)\r
        {\r
-               if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == FFFTP_SUCCESS)\r
+               // IPv6対応\r
+//             if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == FFFTP_SUCCESS)\r
+               if(GetAdrsAndPort(Pkt->ctrl_skt, Buf, Adrs, &Port, 39) == FFFTP_SUCCESS)\r
                {\r
                        if((data_socket = connectsock(Adrs, Port, MSGJPN091, CancelCheckWork)) != INVALID_SOCKET)\r
                        {\r
@@ -1091,14 +1524,16 @@ static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)
                                        iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
                                        if(iRetCode/100 == FTP_PRELIM)\r
                                        {\r
+                                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                                               ReleaseMutex(hListAccMutex);\r
                                                // FTPS対応\r
 //                                             iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
-                                               if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
+                                               if(IsSSLAttached(Pkt->ctrl_skt))\r
                                                {\r
-                                                       if(AttachSSL(data_socket))\r
+                                                       if(AttachSSL(data_socket, Pkt->ctrl_skt, CancelCheckWork))\r
                                                                iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
                                                        else\r
-                                                               iRetCode = FTP_ERROR;\r
+                                                               iRetCode = 500;\r
                                                }\r
                                                else\r
                                                        iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
@@ -1204,12 +1639,18 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                char Buf3[(BUFSIZE + 3) * 4];\r
                CODECONVINFO cInfo2;\r
                int ProcessedBOM = NO;\r
+               // 4GB超対応(kaokunさん提供)\r
+               DWORD High = 0;\r
                if(CreateMode == OPEN_ALWAYS)\r
-                       SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
+                       // 4GB超対応(kaokunさん提供)\r
+//                     SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
+                       SetFilePointer(iFileHandle, 0, &High, FILE_END);\r
 \r
                if(Pkt->hWndTrans != NULL)\r
                {\r
-                       TimeStart = time(NULL);\r
+                       // 同時接続対応\r
+//                     TimeStart = time(NULL);\r
+                       TimeStart[Pkt->ThreadCount] = time(NULL);\r
                        SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
                }\r
 \r
@@ -1281,8 +1722,6 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
 //                                             Continue = ConvJIStoSJIS(&cInfo);\r
 //                                     else\r
 //                                             Continue = ConvEUCtoSJIS(&cInfo);\r
-                                       char Buf3[(BUFSIZE + 3) * 4];\r
-                                       CODECONVINFO cInfo2;\r
                                        switch(Pkt->KanjiCode)\r
                                        {\r
                                        case KANJI_SJIS:\r
@@ -1311,6 +1750,11 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                        cInfo2.OutLen = cInfo.OutLen;\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvSJIStoUTF8N(&cInfo);\r
+                                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -1354,6 +1798,14 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                        ConvSJIStoEUC(&cInfo2);\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvJIStoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -1400,6 +1852,14 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                        ConvSJIStoEUC(&cInfo2);\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvEUCtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -1418,6 +1878,50 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                }\r
                                                break;\r
                                        case KANJI_UTF8N:\r
+                                               switch(Pkt->KanjiCodeDesired)\r
+                                               {\r
+                                               case KANJI_SJIS:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                                       break;\r
+                                               case KANJI_JIS:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoJIS(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_EUC:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoEUC(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8N:\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
+                                                       if(ProcessedBOM == NO)\r
+                                                       {\r
+                                                               memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
+                                                               cInfo2.OutLen = 3;\r
+                                                               Continue = YES;\r
+                                                               ProcessedBOM = YES;\r
+                                                               break;\r
+                                                       }\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
+                                               }\r
+                                               break;\r
+                                       case KANJI_UTF8BOM:\r
                                                if(ProcessedBOM == NO)\r
                                                {\r
                                                        if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
@@ -1428,7 +1932,7 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                        cInfo2.OutLen = 0;\r
                                                        switch(Pkt->KanjiCodeDesired)\r
                                                        {\r
-                                                       case KANJI_UTF8N:\r
+                                                       case KANJI_UTF8BOM:\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
                                                                cInfo2.OutLen = 3;\r
                                                                break;\r
@@ -1465,6 +1969,11 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                                        cInfo2.OutLen = cInfo.StrLen;\r
                                                        Continue = NO;\r
                                                        break;\r
+                                               case KANJI_UTF8BOM:\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
                                                }\r
                                                break;\r
                                        }\r
@@ -1482,7 +1991,9 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
 \r
                        Pkt->ExistSize += iNumBytes;\r
                        if(Pkt->hWndTrans != NULL)\r
-                               AllTransSizeNow += iNumBytes;\r
+                               // 同時接続対応\r
+//                             AllTransSizeNow += iNumBytes;\r
+                               AllTransSizeNow[Pkt->ThreadCount] += iNumBytes;\r
                        else\r
                        {\r
                                /* 転送ダイアログを出さない時の経過表示 */\r
@@ -1524,6 +2035,10 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                        memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
                                        cInfo2.OutLen = cInfo.OutLen;\r
                                        break;\r
+                               case KANJI_UTF8BOM:\r
+                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                       break;\r
                                }\r
                                break;\r
                        case KANJI_JIS:\r
@@ -1555,6 +2070,13 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                        cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
                                        ConvSJIStoUTF8N(&cInfo2);\r
                                        break;\r
+                               case KANJI_UTF8BOM:\r
+                                       cInfo2.Str = cInfo.Buf;\r
+                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                       cInfo2.Buf = Buf3;\r
+                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                       break;\r
                                }\r
                                break;\r
                        case KANJI_EUC:\r
@@ -1586,6 +2108,13 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                        cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
                                        ConvSJIStoUTF8N(&cInfo2);\r
                                        break;\r
+                               case KANJI_UTF8BOM:\r
+                                       cInfo2.Str = cInfo.Buf;\r
+                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                       cInfo2.Buf = Buf3;\r
+                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                       break;\r
                                }\r
                                break;\r
                        case KANJI_UTF8N:\r
@@ -1613,6 +2142,41 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                                        memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
                                        cInfo2.OutLen = cInfo.OutLen;\r
                                        break;\r
+                               case KANJI_UTF8BOM:\r
+                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                       break;\r
+                               }\r
+                               break;\r
+                       case KANJI_UTF8BOM:\r
+                               switch(Pkt->KanjiCodeDesired)\r
+                               {\r
+                               case KANJI_SJIS:\r
+                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                       break;\r
+                               case KANJI_JIS:\r
+                                       cInfo2.Str = cInfo.Buf;\r
+                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                       cInfo2.Buf = Buf3;\r
+                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                       ConvSJIStoJIS(&cInfo2);\r
+                                       break;\r
+                               case KANJI_EUC:\r
+                                       cInfo2.Str = cInfo.Buf;\r
+                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                       cInfo2.Buf = Buf3;\r
+                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                       ConvSJIStoEUC(&cInfo2);\r
+                                       break;\r
+                               case KANJI_UTF8N:\r
+                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                       break;\r
+                               case KANJI_UTF8BOM:\r
+                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                       break;\r
                                }\r
                                break;\r
                        }\r
@@ -1631,7 +2195,9 @@ static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc
                {\r
                        KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
                        DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
-                       TimeStart = time(NULL) - TimeStart + 1;\r
+                       // 同時接続対応\r
+//                     TimeStart = time(NULL) - TimeStart + 1;\r
+                       TimeStart[Pkt->ThreadCount] = time(NULL) - TimeStart[Pkt->ThreadCount] + 1;\r
                }\r
                else\r
                {\r
@@ -1720,29 +2286,60 @@ static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
                        if (AskHostType() == HTYPE_VMS)\r
                                return;\r
 #endif\r
+#if defined(HAVE_TANDEM)\r
+                       /* HP Nonstop Server の場合、ファイルのない subvol へ移動すると550 File not found\r
+                        * になるが問題ないのでエラーダイアログやエラーメッセージを出さないため */\r
+                       if (AskHostType() == HTYPE_TANDEM)\r
+                               return;\r
+#endif\r
 \r
                        if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
                        {\r
                                SetTaskMsg(MSGJPN097);\r
                                strcpy(Fname, MSGJPN098);\r
                        }\r
-                       else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
-                               SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       // 同時接続対応\r
+//                     else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
+//                             SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       else if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
+                               SetTaskMsg(MSGJPN099, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
                        else\r
                                SetTaskMsg(MSGJPN100);\r
 \r
                        if(Pkt->Abort != ABORT_USER)\r
                        {\r
-                               if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
-                                       ClearAll = YES;\r
+                               // 全て中止を選択後にダイアログが表示されるバグ対策\r
+//                             if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
+                               // 再転送対応\r
+//                             if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO && DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
+//                                     ClearAll = YES;\r
+                               if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO)\r
+                               {\r
+                                       if(strncmp(Pkt->Cmd, "RETR", 4) == 0 || strncmp(Pkt->Cmd, "STOR", 4) == 0)\r
+                                       {\r
+                                               if(TransferErrorNotify == YES && DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Pkt) == NO)\r
+                                                       ClearAll = YES;\r
+                                               else\r
+                                               {\r
+                                                       Pkt->Mode = TransferErrorMode;\r
+                                                       AddTransFileList(Pkt);\r
+                                               }\r
+                                       }\r
+                               }\r
                        }\r
                }\r
                else\r
                {\r
                        if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
                                SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
-                       else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
-                               SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       // 同時接続対応\r
+//                     else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
+//                             SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       else if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
+                               // "0 B/S"と表示されるバグを修正\r
+                               // 原因は%dにあたる部分に64ビット値が渡されているため\r
+//                             SetTaskMsg(MSGJPN102, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
+                               SetTaskMsg(MSGJPN102, (LONG)TimeStart[Pkt->ThreadCount], (LONG)(Pkt->ExistSize/TimeStart[Pkt->ThreadCount]));\r
                        else\r
                                SetTaskMsg(MSGJPN103, Pkt->ExistSize);\r
                }\r
@@ -1762,13 +2359,17 @@ static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
 *              int ステータス (YES=中止/NO=全て中止)\r
 *----------------------------------------------------------------------------*/\r
 \r
-static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
+// 再転送対応\r
+//static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
+static int DispUpDownErrDialog(int ResID, HWND hWnd, TRANSPACKET *Pkt)\r
 {\r
        if(hWnd == NULL)\r
                hWnd = GetMainHwnd();\r
 \r
        SoundPlay(SND_ERROR);\r
-       return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
+       // 再転送対応\r
+//     return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
+       return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Pkt));\r
 }\r
 \r
 \r
@@ -1784,29 +2385,57 @@ static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)
 *              BOOL TRUE/FALSE\r
 *----------------------------------------------------------------------------*/\r
 \r
-static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+// 64ビット対応\r
+//static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+static INT_PTR CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
+       static TRANSPACKET *Pkt;\r
+       static const RADIOBUTTON DownExistButton[] = {\r
+               { DOWN_EXIST_OVW, EXIST_OVW },\r
+               { DOWN_EXIST_RESUME, EXIST_RESUME },\r
+               { DOWN_EXIST_IGNORE, EXIST_IGNORE }\r
+       };\r
+       #define DOWNEXISTBUTTONS        (sizeof(DownExistButton)/sizeof(RADIOBUTTON))\r
+\r
        switch (message)\r
        {\r
                case WM_INITDIALOG :\r
-                       SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
-                       SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
+                       Pkt = (TRANSPACKET *)lParam;\r
+//                     SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
+                       SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)Pkt->RemoteFile);\r
+                       // 同時接続対応\r
+//                     SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
+                       SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)GetErrMsg());\r
+\r
+                       if((Pkt->Type == TYPE_A) || (Pkt->ExistSize <= 0))\r
+                               EnableWindow(GetDlgItem(hDlg, DOWN_EXIST_RESUME), FALSE);\r
+\r
+                       SetRadioButtonByValue(hDlg, TransferErrorMode, DownExistButton, DOWNEXISTBUTTONS);\r
                        return(TRUE);\r
 \r
                case WM_COMMAND :\r
                        switch(GET_WM_COMMAND_ID(wParam, lParam))\r
                        {\r
+                               case IDOK_ALL :\r
+                                       TransferErrorNotify = NO;\r
+                                       /* ここに break はない */\r
+\r
                                case IDOK :\r
+                                       TransferErrorMode = AskRadioButtonValue(hDlg, DownExistButton, DOWNEXISTBUTTONS);\r
                                        EndDialog(hDlg, YES);\r
                                        break;\r
 \r
                                case IDCANCEL :\r
                                        EndDialog(hDlg, NO);\r
                                        break;\r
+\r
+                               case IDHELP :\r
+//                                     hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000009);\r
+                                       break;\r
                        }\r
-                       return(TRUE);\r
+            return(TRUE);\r
        }\r
-    return(FALSE);\r
+       return(FALSE);\r
 }\r
 \r
 \r
@@ -1874,7 +2503,9 @@ static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int
 *              BOOL TRUE/FALSE\r
 *----------------------------------------------------------------------------*/\r
 \r
-static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+// 64ビット対応\r
+//static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+static INT_PTR CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
 {\r
        switch (iMessage)\r
        {\r
@@ -1927,7 +2558,9 @@ static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)
                        if(Pkt->Type == TYPE_I)\r
                                Pkt->KanjiCode = KANJI_NOCNV;\r
 \r
-                       iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
+                       // 同時接続対応\r
+//                     iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
+                       iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "TYPE %c", Pkt->Type);\r
                        if(iRetCode/100 < FTP_RETRY)\r
                        {\r
                                if(Pkt->Mode == EXIST_UNIQUE)\r
@@ -1936,7 +2569,13 @@ static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)
                                if(Pkt->hWndTrans != NULL)\r
                                        DispTransFileInfo(Pkt, MSGJPN104, TRUE, YES);\r
 \r
-                               if(BackgrndMessageProc() == NO)\r
+                               // SFTP対応\r
+//                             if(BackgrndMessageProc() == NO)\r
+                               if(IsSFTPAttached(Pkt->ctrl_skt))\r
+                               {\r
+                                       // TODO:\r
+                               }\r
+                               else if(BackgrndMessageProc() == NO)\r
                                {\r
                                        if(AskPasvMode() != YES)\r
                                                iRetCode = UpLoadNonPassive(Pkt);\r
@@ -1951,7 +2590,9 @@ static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)
 \r
                        /* 属性変更 */\r
                        if((Pkt->Attr != -1) && ((iRetCode/100) == FTP_COMPLETE))\r
-                               command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
+                               // 同時接続対応\r
+//                             command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
+                               command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
                }\r
                else\r
                {\r
@@ -1988,25 +2629,56 @@ static int UpLoadNonPassive(TRANSPACKET *Pkt)
        SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
        SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
        char Buf[1024];\r
-       struct sockaddr_in saSockAddr1;\r
+       // IPv6対応\r
+//     struct sockaddr_in saSockAddr1;\r
+       struct sockaddr_in saSockAddrIPv4;\r
+       struct sockaddr_in6 saSockAddrIPv6;\r
        int Resume;\r
        char Reply[ERR_MSG_LEN+7];\r
 \r
-       if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled)) != INVALID_SOCKET)\r
+       // 同時接続対応\r
+//     if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled)) != INVALID_SOCKET)\r
+       if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled[Pkt->ThreadCount])) != INVALID_SOCKET)\r
        {\r
                SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
                if(Resume == NO)\r
+#if defined(HAVE_TANDEM)\r
+                       if(AskHostType() == HTYPE_TANDEM && AskOSS() == NO && Pkt->Type != TYPE_A) {\r
+                               if( Pkt->PriExt == DEF_PRIEXT && Pkt->SecExt == DEF_SECEXT && Pkt->MaxExt == DEF_MAXEXT) {\r
+                                       // EXTENTがデフォルトのときはコードのみ\r
+                                       sprintf(Buf, "%s%s,%d", Pkt->Cmd, Pkt->RemoteFile, Pkt->FileCode);\r
+                               } else {\r
+                                       sprintf(Buf, "%s%s,%d,%d,%d,%d", Pkt->Cmd, Pkt->RemoteFile, Pkt->FileCode, Pkt->PriExt, Pkt->SecExt, Pkt->MaxExt);\r
+                               }\r
+                       } else\r
+#endif\r
                        sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
                else\r
                        sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
 \r
-               iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
+               // 同時接続対応\r
+//             iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
+               iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "%s", Buf);\r
                if((iRetCode/100) == FTP_PRELIM)\r
                {\r
-                       if(SocksGet2ndBindReply(listen_socket, &data_socket) == FFFTP_FAIL)\r
+                       // 同時接続対応\r
+//                     if(SocksGet2ndBindReply(listen_socket, &data_socket) == FFFTP_FAIL)\r
+                       if(SocksGet2ndBindReply(listen_socket, &data_socket, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                        {\r
-                               iLength=sizeof(saSockAddr1);\r
-                               data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
+                               // IPv6対応\r
+//                             iLength=sizeof(saSockAddr1);\r
+//                             data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
+                               switch(AskCurNetType())\r
+                               {\r
+                               case NTYPE_IPV4:\r
+                                       iLength=sizeof(saSockAddrIPv4);\r
+                                       data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv4, (int *)&iLength);\r
+                                       break;\r
+                               case NTYPE_IPV6:\r
+                                       iLength=sizeof(saSockAddrIPv6);\r
+                                       data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv6, (int *)&iLength);\r
+                                       break;\r
+                               }\r
 \r
                                if(shutdown(listen_socket, 1) != 0)\r
                                        ReportWSError("shutdown listen", WSAGetLastError());\r
@@ -2019,19 +2691,33 @@ static int UpLoadNonPassive(TRANSPACKET *Pkt)
                                        iRetCode = 500;\r
                                }\r
                                else\r
-                                       DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
+                                       // IPv6対応\r
+//                                     DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
+                               {\r
+                                       switch(AskCurNetType())\r
+                                       {\r
+                                       case NTYPE_IPV4:\r
+                                               DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddrIPv4.sin_addr), ntohs(saSockAddrIPv4.sin_port));\r
+                                               break;\r
+                                       case NTYPE_IPV6:\r
+                                               DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet6_ntoa(saSockAddrIPv6.sin6_addr), ntohs(saSockAddrIPv6.sin6_port));\r
+                                               break;\r
+                                       }\r
+                               }\r
                        }\r
 \r
                        if(data_socket != INVALID_SOCKET)\r
                        {\r
+                               // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                               ReleaseMutex(hListAccMutex);\r
                                // FTPS対応\r
 //                             iRetCode = UpLoadFile(Pkt, data_socket);\r
-                               if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
+                               if(IsSSLAttached(Pkt->ctrl_skt))\r
                                {\r
-                                       if(AttachSSL(data_socket))\r
+                                       if(AttachSSL(data_socket, Pkt->ctrl_skt, &Canceled[Pkt->ThreadCount]))\r
                                                iRetCode = UpLoadFile(Pkt, data_socket);\r
                                        else\r
-                                               iRetCode = FTP_ERROR;\r
+                                               iRetCode = 500;\r
                                }\r
                                else\r
                                        iRetCode = UpLoadFile(Pkt, data_socket);\r
@@ -2071,18 +2757,36 @@ static int UpLoadPassive(TRANSPACKET *Pkt)
        int iRetCode;\r
        SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
        char Buf[1024];\r
-       char Adrs[20];\r
+       // IPv6対応\r
+//     char Adrs[20];\r
+       char Adrs[40];\r
        int Port;\r
        int Flg;\r
        int Resume;\r
        char Reply[ERR_MSG_LEN+7];\r
 \r
-       iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled, "PASV");\r
+       // 同時接続対応\r
+//     iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled, "PASV");\r
+       // IPv6対応\r
+//     iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled[Pkt->ThreadCount], "PASV");\r
+       switch(AskCurNetType())\r
+       {\r
+       case NTYPE_IPV4:\r
+               iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled[Pkt->ThreadCount], "PASV");\r
+               break;\r
+       case NTYPE_IPV6:\r
+               iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled[Pkt->ThreadCount], "EPSV");\r
+               break;\r
+       }\r
        if(iRetCode/100 == FTP_COMPLETE)\r
        {\r
-               if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == FFFTP_SUCCESS)\r
+               // IPv6対応\r
+//             if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == FFFTP_SUCCESS)\r
+               if(GetAdrsAndPort(Pkt->ctrl_skt, Buf, Adrs, &Port, 39) == FFFTP_SUCCESS)\r
                {\r
-                       if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled)) != INVALID_SOCKET)\r
+                       // 同時接続対応\r
+//                     if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled)) != INVALID_SOCKET)\r
+                       if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled[Pkt->ThreadCount])) != INVALID_SOCKET)\r
                        {\r
                                // 変数が未初期化のバグ修正\r
                                Flg = 1;\r
@@ -2091,21 +2795,35 @@ static int UpLoadPassive(TRANSPACKET *Pkt)
 \r
                                SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
                                if(Resume == NO)\r
+#if defined(HAVE_TANDEM)\r
+                                       if(AskHostType() == HTYPE_TANDEM && AskOSS() == NO && Pkt->Type != TYPE_A) {\r
+                                               if( Pkt->PriExt == DEF_PRIEXT && Pkt->SecExt == DEF_SECEXT && Pkt->MaxExt == DEF_MAXEXT) {\r
+                                                       // EXTENTがデフォルトのときはコードのみ\r
+                                                       sprintf(Buf, "%s%s,%d", Pkt->Cmd, Pkt->RemoteFile, Pkt->FileCode);\r
+                                               } else {\r
+                                                       sprintf(Buf, "%s%s,%d,%d,%d,%d", Pkt->Cmd, Pkt->RemoteFile, Pkt->FileCode, Pkt->PriExt, Pkt->SecExt, Pkt->MaxExt);\r
+                                               }\r
+                                       } else\r
+#endif\r
                                        sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
                                else\r
                                        sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
 \r
-                               iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
+                               // 同時接続対応\r
+//                             iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
+                               iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "%s", Buf);\r
                                if(iRetCode/100 == FTP_PRELIM)\r
                                {\r
+                                       // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
+                                       ReleaseMutex(hListAccMutex);\r
                                        // FTPS対応\r
 //                                     iRetCode = UpLoadFile(Pkt, data_socket);\r
-                                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
+                                       if(IsSSLAttached(Pkt->ctrl_skt))\r
                                        {\r
-                                               if(AttachSSL(data_socket))\r
+                                               if(AttachSSL(data_socket, Pkt->ctrl_skt, &Canceled[Pkt->ThreadCount]))\r
                                                        iRetCode = UpLoadFile(Pkt, data_socket);\r
                                                else\r
-                                                       iRetCode = FTP_ERROR;\r
+                                                       iRetCode = 500;\r
                                        }\r
                                        else\r
                                                iRetCode = UpLoadFile(Pkt, data_socket);\r
@@ -2212,8 +2930,11 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                        Low = (DWORD)LOW32(Pkt->ExistSize);\r
                        SetFilePointer(iFileHandle, Low, &High, FILE_BEGIN);\r
 \r
-                       AllTransSizeNow = 0;\r
-                       TimeStart = time(NULL);\r
+                       // 同時接続対応\r
+//                     AllTransSizeNow = 0;\r
+//                     TimeStart = time(NULL);\r
+                       AllTransSizeNow[Pkt->ThreadCount] = 0;\r
+                       TimeStart[Pkt->ThreadCount] = time(NULL);\r
                        SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
                }\r
 \r
@@ -2283,6 +3004,11 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                        cInfo2.OutLen = cInfo.OutLen;\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvSJIStoUTF8N(&cInfo);\r
+                                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -2326,6 +3052,14 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                        ConvSJIStoEUC(&cInfo2);\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvJIStoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -2372,6 +3106,14 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                        ConvSJIStoEUC(&cInfo2);\r
                                                        break;\r
                                                case KANJI_UTF8N:\r
+                                                       Continue = ConvEUCtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoUTF8N(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
                                                        if(ProcessedBOM == NO)\r
                                                        {\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
@@ -2390,6 +3132,50 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                }\r
                                                break;\r
                                        case KANJI_UTF8N:\r
+                                               switch(Pkt->KanjiCode)\r
+                                               {\r
+                                               case KANJI_SJIS:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                                       cInfo2.OutLen = cInfo.OutLen;\r
+                                                       break;\r
+                                               case KANJI_JIS:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoJIS(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_EUC:\r
+                                                       Continue = ConvUTF8NtoSJIS(&cInfo);\r
+                                                       cInfo2.Str = cInfo.Buf;\r
+                                                       cInfo2.StrLen = cInfo.OutLen;\r
+                                                       cInfo2.Buf = Buf3;\r
+                                                       cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                                       ConvSJIStoEUC(&cInfo2);\r
+                                                       break;\r
+                                               case KANJI_UTF8N:\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
+                                               case KANJI_UTF8BOM:\r
+                                                       if(ProcessedBOM == NO)\r
+                                                       {\r
+                                                               memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
+                                                               cInfo2.OutLen = 3;\r
+                                                               Continue = YES;\r
+                                                               ProcessedBOM = YES;\r
+                                                               break;\r
+                                                       }\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
+                                               }\r
+                                               break;\r
+                                       case KANJI_UTF8BOM:\r
                                                if(ProcessedBOM == NO)\r
                                                {\r
                                                        if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
@@ -2400,7 +3186,7 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                        cInfo2.OutLen = 0;\r
                                                        switch(Pkt->KanjiCode)\r
                                                        {\r
-                                                       case KANJI_UTF8N:\r
+                                                       case KANJI_UTF8BOM:\r
                                                                memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
                                                                cInfo2.OutLen = 3;\r
                                                                break;\r
@@ -2437,12 +3223,17 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                        cInfo2.OutLen = cInfo.StrLen;\r
                                                        Continue = NO;\r
                                                        break;\r
+                                               case KANJI_UTF8BOM:\r
+                                                       memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
+                                                       cInfo2.OutLen = cInfo.StrLen;\r
+                                                       Continue = NO;\r
+                                                       break;\r
                                                }\r
                                                break;\r
                                        }\r
 \r
 //                                     if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FFFTP_FAIL)\r
-                                       if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FFFTP_FAIL)\r
+                                       if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                                        {\r
                                                Pkt->Abort = ABORT_ERROR;\r
                                                        break;\r
@@ -2452,13 +3243,17 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                        }\r
                        else\r
                        {\r
-                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf, iNumBytes, Pkt->Type) == FFFTP_FAIL)\r
+                               // 同時接続対応\r
+//                             if(TermCodeConvAndSend(&tInfo, dSkt, Buf, iNumBytes, Pkt->Type) == FFFTP_FAIL)\r
+                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf, iNumBytes, Pkt->Type, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                                        Pkt->Abort = ABORT_ERROR;\r
                        }\r
 \r
                        Pkt->ExistSize += iNumBytes;\r
                        if(Pkt->hWndTrans != NULL)\r
-                               AllTransSizeNow += iNumBytes;\r
+                               // 同時接続対応\r
+//                             AllTransSizeNow += iNumBytes;\r
+                               AllTransSizeNow[Pkt->ThreadCount] += iNumBytes;\r
 \r
                        if(BackgrndMessageProc() == YES)\r
                                ForceAbort = YES;\r
@@ -2500,6 +3295,10 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
                                                cInfo2.OutLen = cInfo.OutLen;\r
                                                break;\r
+                                       case KANJI_UTF8BOM:\r
+                                               memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                               cInfo2.OutLen = cInfo.OutLen;\r
+                                               break;\r
                                        }\r
                                        break;\r
                                case KANJI_JIS:\r
@@ -2531,6 +3330,13 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
                                                ConvSJIStoUTF8N(&cInfo2);\r
                                                break;\r
+                                       case KANJI_UTF8BOM:\r
+                                               cInfo2.Str = cInfo.Buf;\r
+                                               cInfo2.StrLen = cInfo.OutLen;\r
+                                               cInfo2.Buf = Buf3;\r
+                                               cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                               ConvSJIStoUTF8N(&cInfo2);\r
+                                               break;\r
                                        }\r
                                        break;\r
                                case KANJI_EUC:\r
@@ -2562,6 +3368,13 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
                                                ConvSJIStoUTF8N(&cInfo2);\r
                                                break;\r
+                                       case KANJI_UTF8BOM:\r
+                                               cInfo2.Str = cInfo.Buf;\r
+                                               cInfo2.StrLen = cInfo.OutLen;\r
+                                               cInfo2.Buf = Buf3;\r
+                                               cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                               ConvSJIStoUTF8N(&cInfo2);\r
+                                               break;\r
                                        }\r
                                        break;\r
                                case KANJI_UTF8N:\r
@@ -2589,24 +3402,61 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                                                memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
                                                cInfo2.OutLen = cInfo.OutLen;\r
                                                break;\r
+                                       case KANJI_UTF8BOM:\r
+                                               memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                               cInfo2.OutLen = cInfo.OutLen;\r
+                                               break;\r
+                                       }\r
+                                       break;\r
+                               case KANJI_UTF8BOM:\r
+                                       switch(Pkt->KanjiCode)\r
+                                       {\r
+                                       case KANJI_SJIS:\r
+                                               memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                               cInfo2.OutLen = cInfo.OutLen;\r
+                                               break;\r
+                                       case KANJI_JIS:\r
+                                               cInfo2.Str = cInfo.Buf;\r
+                                               cInfo2.StrLen = cInfo.OutLen;\r
+                                               cInfo2.Buf = Buf3;\r
+                                               cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                               ConvSJIStoJIS(&cInfo2);\r
+                                               break;\r
+                                       case KANJI_EUC:\r
+                                               cInfo2.Str = cInfo.Buf;\r
+                                               cInfo2.StrLen = cInfo.OutLen;\r
+                                               cInfo2.Buf = Buf3;\r
+                                               cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
+                                               ConvSJIStoEUC(&cInfo2);\r
+                                               break;\r
+                                       case KANJI_UTF8N:\r
+                                               memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                               cInfo2.OutLen = cInfo.OutLen;\r
+                                               break;\r
+                                       case KANJI_UTF8BOM:\r
+                                               memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
+                                               cInfo2.OutLen = cInfo.OutLen;\r
+                                               break;\r
                                        }\r
                                        break;\r
                                }\r
 \r
 //                             if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FFFTP_FAIL)\r
-                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FFFTP_FAIL)\r
+                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                                        Pkt->Abort = ABORT_ERROR;\r
                                cInfo2.Buf = Buf3;\r
                                cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
                                FlushRestData(&cInfo2);\r
-                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FFFTP_FAIL)\r
+                               if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                                        Pkt->Abort = ABORT_ERROR;\r
                        }\r
 \r
                        tInfo.Buf = Buf2;\r
                        tInfo.BufSize = BUFSIZE+3;\r
                        FlushRestTermCodeConvData(&tInfo);\r
-                       if(SendData(dSkt, Buf2, tInfo.OutLen, 0, &Canceled) == FFFTP_FAIL)\r
+                       // 同時接続対応\r
+//                     if(SendData(dSkt, Buf2, tInfo.OutLen, 0, &Canceled) == FFFTP_FAIL)\r
+                       if(SendData(dSkt, Buf2, tInfo.OutLen, 0, &Canceled[Pkt->ThreadCount]) == FFFTP_FAIL)\r
                                Pkt->Abort = ABORT_ERROR;\r
                }\r
 \r
@@ -2615,7 +3465,9 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                {\r
                        KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
                        DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
-                       TimeStart = time(NULL) - TimeStart + 1;\r
+                       // 同時接続対応\r
+//                     TimeStart = time(NULL) - TimeStart + 1;\r
+                       TimeStart[Pkt->ThreadCount] = time(NULL) - TimeStart[Pkt->ThreadCount] + 1;\r
                }\r
                CloseHandle(iFileHandle);\r
        }\r
@@ -2635,7 +3487,9 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
                ;\r
 #endif\r
 \r
-       iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, &Canceled, TmpBuf);\r
+       // 同時接続対応\r
+//     iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, &Canceled, TmpBuf);\r
+       iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, &Canceled[Pkt->ThreadCount], TmpBuf);\r
 \r
 //#pragma aaa\r
 //DoPrintf("##UP REPLY : %s", Buf);\r
@@ -2663,7 +3517,9 @@ static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)
 *              int 応答コード\r
 *----------------------------------------------------------------------------*/\r
 \r
-static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii)\r
+// 同時接続対応\r
+//static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii)\r
+static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii, int *CancelCheckWork)\r
 {\r
        char Buf3[BUFSIZE*2];\r
        int Continue;\r
@@ -2681,13 +3537,17 @@ static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data,
                do\r
                {\r
                        Continue = ConvTermCodeToCRLF(tInfo);\r
-                       if((Ret = SendData(Skt, Buf3, tInfo->OutLen, 0, &Canceled)) == FFFTP_FAIL)\r
+                       // 同時接続対応\r
+//                     if((Ret = SendData(Skt, Buf3, tInfo->OutLen, 0, &Canceled)) == FFFTP_FAIL)\r
+                       if((Ret = SendData(Skt, Buf3, tInfo->OutLen, 0, CancelCheckWork)) == FFFTP_FAIL)\r
                                break;\r
                }\r
                while(Continue == YES);\r
        }\r
        else\r
-               Ret = SendData(Skt, Data, Size, 0, &Canceled);\r
+               // 同時接続対応\r
+//             Ret = SendData(Skt, Data, Size, 0, &Canceled);\r
+               Ret = SendData(Skt, Data, Size, 0, CancelCheckWork);\r
 \r
        return(Ret);\r
 }\r
@@ -2709,21 +3569,46 @@ static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
        {\r
                if((iRetCode/100) >= FTP_CONTINUE)\r
                {\r
-                       if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
-                               SetTaskMsg(MSGJPN113, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       // 同時接続対応\r
+//                     if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
+//                             SetTaskMsg(MSGJPN113, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
+                               SetTaskMsg(MSGJPN113, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
                        else\r
                                SetTaskMsg(MSGJPN114);\r
 \r
                        if(Pkt->Abort != ABORT_USER)\r
                        {\r
-                               if(DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt->LocalFile) == NO)\r
-                                       ClearAll = YES;\r
+                               // 全て中止を選択後にダイアログが表示されるバグ対策\r
+//                             if(DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt->LocalFile) == NO)\r
+                               // 再転送対応\r
+//                             if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO && DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt->LocalFile) == NO)\r
+//                                     ClearAll = YES;\r
+                               if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO)\r
+                               {\r
+                                       if(strncmp(Pkt->Cmd, "RETR", 4) == 0 || strncmp(Pkt->Cmd, "STOR", 4) == 0)\r
+                                       {\r
+                                               if(TransferErrorNotify == YES && DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt) == NO)\r
+                                                       ClearAll = YES;\r
+                                               else\r
+                                               {\r
+                                                       Pkt->Mode = TransferErrorMode;\r
+                                                       AddTransFileList(Pkt);\r
+                                               }\r
+                                       }\r
+                               }\r
                        }\r
                }\r
                else\r
                {\r
-                       if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
-                               SetTaskMsg(MSGJPN115, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       // 同時接続対応\r
+//                     if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
+//                             SetTaskMsg(MSGJPN115, TimeStart, Pkt->ExistSize/TimeStart);\r
+                       if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
+                               // "0 B/S"と表示されるバグを修正\r
+                               // 原因は%dにあたる部分に64ビット値が渡されているため\r
+//                             SetTaskMsg(MSGJPN115, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
+                               SetTaskMsg(MSGJPN115, (LONG)TimeStart[Pkt->ThreadCount], (LONG)(Pkt->ExistSize/TimeStart[Pkt->ThreadCount]));\r
                        else\r
                                SetTaskMsg(MSGJPN116);\r
                }\r
@@ -2780,7 +3665,10 @@ static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM
        RECT RectDlg;\r
        RECT RectPar;\r
        HMENU hMenu;\r
-       static TRANSPACKET *Pkt;\r
+       // 同時接続対応\r
+//     static TRANSPACKET *Pkt;\r
+       TRANSPACKET *Pkt;\r
+       int i;\r
 \r
        switch(Msg)\r
        {\r
@@ -2809,11 +3697,18 @@ static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM
 \r
                                case TRANS_STOP_ALL :\r
                                        ClearAll = YES;\r
+                                       for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
+                                               Canceled[i] = YES;\r
                                        /* ここに break はない */\r
 \r
                                case IDCANCEL :\r
+                                       // 64ビット対応\r
+//                                     if(!(Pkt = (TRANSPACKET*)GetWindowLong(hDlg, GWL_USERDATA)))\r
+                                       if(!(Pkt = (TRANSPACKET*)GetWindowLongPtr(hDlg, GWLP_USERDATA)))\r
+                                               break;\r
                                        Pkt->Abort = ABORT_USER;\r
-                                       Canceled = YES;\r
+//                                     Canceled = YES;\r
+                                       Canceled[Pkt->ThreadCount] = YES;\r
                                        break;\r
                        }\r
                        break;\r
@@ -2825,13 +3720,22 @@ static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM
                                        SetForegroundWindow(hDlg);\r
                                MoveToForeground = NO;\r
                                KillTimer(hDlg, TIMER_DISPLAY);\r
+                               // 64ビット対応\r
+//                             if(!(Pkt = (TRANSPACKET*)GetWindowLong(hDlg, GWL_USERDATA)))\r
+                               if(!(Pkt = (TRANSPACKET*)GetWindowLongPtr(hDlg, GWLP_USERDATA)))\r
+                                       break;\r
+                               if(Canceled[Pkt->ThreadCount] == YES)\r
+                                       Pkt->Abort = ABORT_USER;\r
                                DispTransferStatus(hDlg, NO, Pkt);\r
                                SetTimer(hDlg, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
                        }\r
                        break;\r
 \r
                case WM_SET_PACKET :\r
-                       Pkt = (TRANSPACKET *)lParam;\r
+//                     Pkt = (TRANSPACKET *)lParam;\r
+                       // 64ビット対応\r
+//                     SetWindowLong(hDlg, GWL_USERDATA, (LONG)lParam);\r
+                       SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)lParam);\r
                        break;\r
        }\r
        return(FALSE);\r
@@ -2874,11 +3778,15 @@ static void DispTransferStatus(HWND hWnd, int End, TRANSPACKET *Pkt)
                {\r
                        if(End == NO)\r
                        {\r
-                               TotalLap = time(NULL) - TimeStart + 1;\r
+                               // 同時接続対応\r
+//                             TotalLap = time(NULL) - TimeStart + 1;\r
+                               TotalLap = time(NULL) - TimeStart[Pkt->ThreadCount] + 1;\r
 \r
                                Bps = 0;\r
                                if(TotalLap != 0)\r
-                                       Bps = AllTransSizeNow / TotalLap;\r
+                                       // 同時接続対応\r
+//                                     Bps = AllTransSizeNow / TotalLap;\r
+                                       Bps = AllTransSizeNow[Pkt->ThreadCount] / TotalLap;\r
                                Transed = Pkt->Size - Pkt->ExistSize;\r
 \r
                                if(Pkt->Size <= 0)\r
@@ -2974,6 +3882,8 @@ static void DispTransFileInfo(TRANSPACKET *Pkt, char *Title, int SkipButton, int
                                SendDlgItemMessage(Pkt->hWndTrans, TRANS_KANJI, WM_SETTEXT, 0, (LPARAM)MSGJPN123);\r
                        else if(Pkt->KanjiCode == KANJI_UTF8N)\r
                                SendDlgItemMessage(Pkt->hWndTrans, TRANS_KANJI, WM_SETTEXT, 0, (LPARAM)MSGJPN306);\r
+                       else if(Pkt->KanjiCode == KANJI_UTF8BOM)\r
+                               SendDlgItemMessage(Pkt->hWndTrans, TRANS_KANJI, WM_SETTEXT, 0, (LPARAM)MSGJPN329);\r
                }\r
                else\r
                {\r
@@ -3000,10 +3910,31 @@ static void DispTransFileInfo(TRANSPACKET *Pkt, char *Title, int SkipButton, int
 *                      FFFTP_SUCCESS/FFFTP_FAIL\r
 *----------------------------------------------------------------------------*/\r
 \r
-static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max)\r
+static int GetAdrsAndPort(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max)\r
+{\r
+       int Result;\r
+       Result = FFFTP_FAIL;\r
+       switch(AskCurNetType())\r
+       {\r
+       case NTYPE_IPV4:\r
+               Result = GetAdrsAndPortIPv4(Skt, Str, Adrs, Port, Max);\r
+               break;\r
+       case NTYPE_IPV6:\r
+               Result = GetAdrsAndPortIPv6(Skt, Str, Adrs, Port, Max);\r
+               break;\r
+       }\r
+       return Result;\r
+}\r
+\r
+\r
+// IPv6対応\r
+//static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max)\r
+static int GetAdrsAndPortIPv4(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max)\r
 {\r
        char *Pos;\r
        char *Btm;\r
+       // コンマではなくドットを返すホストがあるため\r
+       char *OldBtm;\r
        int Sts;\r
 \r
        Sts = FFFTP_FAIL;\r
@@ -3013,18 +3944,36 @@ static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max)
        {\r
                Pos++;\r
                Btm = strchr(Pos, ',');\r
+               // コンマではなくドットを返すホストがあるため\r
+               if(Btm == NULL)\r
+                       Btm = strchr(Pos, '.');\r
                if(Btm != NULL)\r
                {\r
                        Btm++;\r
-                       Btm = strchr(Btm, ',');\r
+                       // コンマではなくドットを返すホストがあるため\r
+//                     Btm = strchr(Btm, ',');\r
+                       OldBtm = Btm;\r
+                       Btm = strchr(OldBtm, ',');\r
+                       if(Btm == NULL)\r
+                               Btm = strchr(OldBtm, '.');\r
                        if(Btm != NULL)\r
                        {\r
                                Btm++;\r
-                               Btm = strchr(Btm, ',');\r
+                               // コンマではなくドットを返すホストがあるため\r
+//                             Btm = strchr(Btm, ',');\r
+                               OldBtm = Btm;\r
+                               Btm = strchr(OldBtm, ',');\r
+                               if(Btm == NULL)\r
+                                       Btm = strchr(OldBtm, '.');\r
                                if(Btm != NULL)\r
                                {\r
                                        Btm++;\r
-                                       Btm = strchr(Btm, ',');\r
+                                       // コンマではなくドットを返すホストがあるため\r
+//                                     Btm = strchr(Btm, ',');\r
+                                       OldBtm = Btm;\r
+                                       Btm = strchr(OldBtm, ',');\r
+                                       if(Btm == NULL)\r
+                                               Btm = strchr(OldBtm, '.');\r
                                        if(Btm != NULL)\r
                                        {\r
                                                if((Btm - Pos) <= Max)\r
@@ -3035,6 +3984,9 @@ static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max)
 \r
                                                        Pos = Btm + 1;\r
                                                        Btm = strchr(Pos, ',');\r
+                                                       // コンマではなくドットを返すホストがあるため\r
+                                                       if(Btm == NULL)\r
+                                                               Btm = strchr(Pos, '.');\r
                                                        if(Btm != NULL)\r
                                                        {\r
                                                                Btm++;\r
@@ -3051,6 +4003,65 @@ static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max)
 }\r
 \r
 \r
+// IPv6対応\r
+static int GetAdrsAndPortIPv6(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max)\r
+{\r
+       char *Pos;\r
+       char *Btm;\r
+       int Sts;\r
+       int i;\r
+       struct sockaddr_in6 SockAddr;\r
+\r
+       Sts = FFFTP_FAIL;\r
+\r
+       Btm = strchr(Str, '(');\r
+       if(Btm != NULL)\r
+       {\r
+               Btm++;\r
+               Btm = strchr(Btm, '|');\r
+               if(Btm != NULL)\r
+               {\r
+                       Pos = Btm + 1;\r
+                       Btm = strchr(Pos, '|');\r
+                       if(Btm != NULL)\r
+                       {\r
+                               Pos = Btm + 1;\r
+                               Btm = strchr(Pos, '|');\r
+                               if(Btm != NULL)\r
+                               {\r
+                                       if((Btm - Pos) <= Max)\r
+                                       {\r
+                                               if((Btm - Pos) > 0)\r
+                                               {\r
+                                                       strncpy(Adrs, Pos, Btm - Pos);\r
+                                                       *(Adrs + (Btm - Pos)) = NUL;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       i = sizeof(SockAddr);\r
+                                                       if(getpeername(Skt, (struct sockaddr*)&SockAddr, &i) != SOCKET_ERROR)\r
+                                                               AddressToStringIPv6(Adrs, &SockAddr.sin6_addr);\r
+                                               }\r
+\r
+                                               Pos = Btm + 1;\r
+                                               Btm = strchr(Pos, '|');\r
+                                               if(Btm != NULL)\r
+                                               {\r
+                                                       Btm++;\r
+                                                       *Port = atoi(Pos);\r
+                                                       Btm = strchr(Btm, ')');\r
+                                                       if(Btm != NULL)\r
+                                                               Sts = FFFTP_SUCCESS;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return(Sts);\r
+}\r
+\r
+\r
 /*----- Windowsのスペシャルデバイスかどうかを返す -----------------------------\r
 *\r
 *      Parameter\r
@@ -3139,7 +4150,9 @@ static int MirrorDelNotify(int Cur, int Notify, TRANSPACKET *Pkt)
 *              BOOL TRUE/FALSE\r
 *----------------------------------------------------------------------------*/\r
 \r
-static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+// 64ビット対応\r
+//static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
+static INT_PTR CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
 {\r
        static MIRRORDELETEINFO *DelInfo;\r
        switch (iMessage)\r
@@ -3192,10 +4205,14 @@ static void SetErrorMsg(char *fmt, ...)
 {\r
        va_list Args;\r
 \r
-       if(strlen(ErrMsg) == 0)\r
+       // 同時接続対応\r
+//     if(strlen(ErrMsg) == 0)\r
+       if(strlen(GetErrMsg()) == 0)\r
        {\r
                va_start(Args, fmt);\r
-               wvsprintf(ErrMsg, fmt, Args);\r
+               // 同時接続対応\r
+//             wvsprintf(ErrMsg, fmt, Args);\r
+               wvsprintf(GetErrMsg(), fmt, Args);\r
                va_end(Args);\r
        }\r
        return;\r
@@ -3237,3 +4254,39 @@ int CheckPathViolation(TRANSPACKET *packet)
 }\r
 \r
 \r
+// 同時接続対応\r
+static char* GetErrMsg()\r
+{\r
+       char* r;\r
+       DWORD ThreadId;\r
+       int i;\r
+       r = NULL;\r
+       WaitForSingleObject(hErrMsgMutex, INFINITE);\r
+       ThreadId = GetCurrentThreadId();\r
+       i = 0;\r
+       while(i < MAX_DATA_CONNECTION + 1)\r
+       {\r
+               if(ErrMsgThreadId[i] == ThreadId)\r
+               {\r
+                       r = ErrMsg[i];\r
+                       break;\r
+               }\r
+               i++;\r
+       }\r
+       if(!r)\r
+       {\r
+               i = 0;\r
+               while(i < MAX_DATA_CONNECTION + 1)\r
+               {\r
+                       if(ErrMsgThreadId[i] == 0)\r
+                       {\r
+                               ErrMsgThreadId[i] = ThreadId;\r
+                               r = ErrMsg[i];\r
+                               break;\r
+                       }\r
+                       i++;\r
+               }\r
+       }\r
+       ReleaseMutex(hErrMsgMutex);\r
+       return r;\r
+}\r