Ticket #1467: filezilla_sftp_utf8.patch

File filezilla_sftp_utf8.patch, 24.6 KB (added by tommywu, 19 years ago)

allow use force UTF8 option in sftp mode

  • FzSFtp/psftp.c

    diff -Nur source/FzSFtp/psftp.c source.patch/FzSFtp/psftp.c
    old new  
    1717#include "int64.h"
    1818
    1919#include "FzSFtpIpc.h"
     20#include <tchar.h>
    2021
    2122/*
    2223 * Since SFTP is a request-response oriented protocol, it requires
     
    389390    sfree(fname);
    390391    return 0;
    391392    }
    392 
     393#ifdef _UNICODE
     394    {
     395        int len;
     396
     397        // convert from UTF-8 to ANSI
     398        len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)outfname, -1, NULL, 0);
     399        if (len != 0)
     400        {
     401            wchar_t *p1;
     402
     403            p1 = malloc(sizeof(wchar_t) * (len*2+1));
     404            MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)outfname, -1 , (LPWSTR)p1, len*2);
     405            if (restart)
     406            fp = CreateFile(p1, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
     407            else
     408            fp = CreateFile(p1, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
     409            free(p1);
     410        }
     411        else {
     412            if (restart)
     413            fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
     414            else
     415            fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
     416        }
     417    }
     418#else
    393419    if (restart)
    394420    fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    395421    else
    396422    fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
    397 
     423#endif
    398424    if (fp==INVALID_HANDLE_VALUE)
    399425    {
    400426    FzSFtpIpc_Error1("Unable to open %s", outfname);
     
    508534    return 0;
    509535    }
    510536
     537#ifdef _UNICODE
     538    {
     539        int len;
     540
     541        // convert from UTF-8 to ANSI
     542        len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)localfile, -1, NULL, 0);
     543        if (len != 0)
     544        {
     545            wchar_t *p1;
     546
     547            p1 = malloc(sizeof(wchar_t) * (len*2+1));
     548            MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)localfile, -1 , (LPWSTR)p1, len*2);
     549            fp = CreateFile(p1, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
     550            free(p1);
     551        }
     552        else {
     553            fp = CreateFileA(localfile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
     554        }
     555    }
     556#else
    511557    fp = CreateFileA(localfile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
     558#endif
    512559    if (fp == INVALID_HANDLE_VALUE)
    513560    {
    514561    FzSFtpIpc_Error1("Unable to open %s", localfile);
  • SFtpIpc.cpp

    diff -Nur source/SFtpIpc.cpp source.patch/SFtpIpc.cpp
    old new  
    146146
    147147    m_hReceiveThread=0;
    148148    m_hExitEvent=0;
     149    m_bUTF8 = pOwner->m_bUTF8;
    149150}
    150151
    151152CSFtpIpc::~CSFtpIpc()
     
    326327    return 0;
    327328}
    328329
    329 BOOL CSFtpIpc::Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData)
     330BOOL CSFtpIpc::Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData, CString status)
    330331{
    331332    USES_CONVERSION;
    332333    ASSERT(m_hSFtpProcess);
     
    336337    ASSERT(!nDataLength || pData);
    337338
    338339    CString str;
    339     if (nID==SFTP_DATAID_STC_CONNECT)
    340         str.Format( _T("CONNECT %s@%s:%d"), A2CT((char *)pData+strlen((char *)pData)+1+4), A2CT((char *)pData), *(int *)((char *)pData+strlen((char *)pData)+1) );
     340    if (nID==SFTP_DATAID_STC_CONNECT) {
     341        if (status == "")
     342            str.Format( _T("CONNECT %s@%s:%d"), A2CT((char *)pData+strlen((char *)pData)+1+4), A2CT((char *)pData), *(int *)((char *)pData+strlen((char *)pData)+1) );
     343        else
     344            str = _T("CONNECT ") + status;
     345    }
    341346    else if (nID==SFTP_DATAID_STC_PWD)
    342347        str="PWD";
    343     else if (nID==SFTP_DATAID_STC_CD)
    344         str=(CString)"CD " + (char *)pData;
     348    else if (nID==SFTP_DATAID_STC_CD) {
     349        if (status == "")
     350            str=(CString)"CD " + (char *)pData;
     351        else
     352            str = _T("CD ") + status;
     353    }
    345354    else if (nID==SFTP_DATAID_STC_LIST)
    346355        str="LIST";
    347     else if (nID==SFTP_DATAID_STC_MKD)
    348         str=(CString)"MKD " + (char *)pData;
    349     else if (nID==SFTP_DATAID_STC_GET)
    350         str.Format( _T("GET %s %s %s"),
     356    else if (nID==SFTP_DATAID_STC_MKD) {
     357        if (status == "")
     358            str=(CString)"MKD " + (char *)pData;
     359        else
     360            str = _T("MKD ") + status;
     361    }
     362    else if (nID==SFTP_DATAID_STC_GET) {
     363        if (status == "")
     364            str.Format( _T("GET %s %s %s"),
    351365                    A2CT((char *)pData),
    352366                    A2CT((char *)pData+strlen((char *)pData)+1),
    353367                    ( *(int *)((char *)pData+strlen((char *)pData)+1+strlen((char *)pData+strlen((char *)pData)+1)+1)?_T("TRUE"):_T("FALSE") ));
    354     else if (nID==SFTP_DATAID_STC_PUT)
    355         str.Format( _T("PUT %s %s %s"),
     368        else
     369            str = _T("GET ") + status;
     370    }
     371    else if (nID==SFTP_DATAID_STC_PUT) {
     372        if (status == "")
     373            str.Format( _T("PUT %s %s %s"),
    356374                    A2CT((char *)pData),
    357375                    A2CT((char *)pData+strlen((char *)pData)+1),
    358376                    ( *(int *)((char *)pData+strlen((char *)pData)+1+strlen((char *)pData+strlen((char *)pData)+1)+1)?_T("TRUE"):_T("FALSE") ));
    359     else if (nID==SFTP_DATAID_STC_DELE)
    360         str=(CString)"DELE " + (char *)pData;
    361     else if (nID==SFTP_DATAID_STC_RMD)
    362         str=(CString)"RMD " + (char *)pData;
    363     else if (nID==SFTP_DATAID_STC_RENAME)
    364         str.Format( _T("RENAME %s %s"),
     377        else
     378            str = _T("PUT ") + status;
     379    }
     380    else if (nID==SFTP_DATAID_STC_DELE) {
     381        if (status == "")
     382            str=(CString)"DELE " + (char *)pData;
     383        else
     384            str = _T("DELE ") + status;
     385    }
     386    else if (nID==SFTP_DATAID_STC_RMD) {
     387        if (status == "")
     388            str=(CString)"RMD " + (char *)pData;
     389        else
     390            str = _T("RMD ") + status;
     391    }
     392    else if (nID==SFTP_DATAID_STC_RENAME) {
     393        if (status == "")
     394            str.Format( _T("RENAME %s %s"),
    365395                    A2CT((char *)pData),
    366396                    A2CT((char *)pData+strlen((char *)pData)+1));
    367     else if (nID==SFTP_DATAID_STC_CHMOD)
    368         str.Format( _T("CHMOD %s %s"),
     397        else
     398            str = _T("RENAME ") + status;
     399    }
     400    else if (nID==SFTP_DATAID_STC_CHMOD) {
     401        if (status == "")
     402            str.Format( _T("CHMOD %s %s"),
    369403                    A2CT((char *)pData),
    370404                    A2CT((char *)pData+strlen((char *)pData)+1));
     405        else
     406            str = _T("CHMOD ") + status;
     407    }
    371408    if (str!="")
    372409        m_pOwner->ShowStatus(str, 2);
    373410       
     
    417454BOOL CSFtpIpc::Send(const DWORD &nID, LPCTSTR str)
    418455{
    419456    USES_CONVERSION;
    420     if (str)
    421         return Send(nID, (const DWORD)strlen(T2CA(str))+1, (LPVOID)T2CA(str));
     457
     458    if (str) {
     459        if (m_bUTF8)
     460        {
     461            bool res;
     462            LPCWSTR unicode = T2CW(str);
     463            int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
     464            char* utf8 = new char[len + 1];
     465            WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
     466
     467            res = Send(nID, (const DWORD)strlen(utf8)+1, (LPVOID)utf8, str);
     468            delete [] utf8;
     469            return res;
     470        }
     471        else
     472        {
     473            return Send(nID, (const DWORD)strlen(T2CA(str))+1, (LPVOID)T2CA(str), str);
     474        }
     475    }
    422476    else
    423477        return Send(nID, 0, 0);
    424478}
  • SFtpIpc.h

    diff -Nur source/SFtpIpc.h source.patch/SFtpIpc.h
    old new  
    3434    friend CSFtpIpcHelperWindow;
    3535public:
    3636    BOOL Send(const DWORD &nID, LPCTSTR str);
    37     BOOL Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData);
     37    BOOL Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData, CString status = "");
    3838    BOOL AttachProcess(HANDLE hSFtpProcess);
    3939    CString GetHandleString();
    4040    CSFtpIpc(CSFtpControlSocket *pOwner);
     
    6464    HANDLE m_hReceiveThread;
    6565    static DWORD WINAPI ReceiveThread( LPVOID pParam );
    6666    HANDLE m_hExitEvent;
     67    bool m_bUTF8;
    6768};
    6869
    6970#endif // !defined(AFX_SFTPIPC_H__71B20B86_C3D8_4197_90C2_349A18548D58__INCLUDED_)
  • SftpControlSocket.cpp

    diff -Nur source/SftpControlSocket.cpp source.patch/SftpControlSocket.cpp
    old new  
    3939class CSFtpControlSocket::CFileTransferData : public CSFtpControlSocket::t_operation::COpData
    4040{
    4141public:
    42     CFileTransferData(t_server server)
     42    CFileTransferData(t_server server, bool bUTF8)
    4343    {
    4444        pDirectoryListing=0;
    4545        nWaitNextOpState=0;
     
    5050        transferdata.nTransferStart=0;
    5151        pStartTime=0;
    5252        bUseAbsolutePaths = FALSE;
    53         pParser = new CFtpListResult(server);
     53        pParser = new CFtpListResult(server, bUTF8);
    5454    };
    5555    virtual ~CFileTransferData()
    5656    {
     
    7979class CSFtpControlSocket::CListData:public CSFtpControlSocket::t_operation::COpData
    8080{
    8181public:
    82     CListData(t_server server)
     82    CListData(t_server server, bool bUTF8)
    8383    {
    8484        pDirectoryListing=0;
    85         pParser = new CFtpListResult(server);
     85        pParser = new CFtpListResult(server, bUTF8);
    8686    }
    8787    virtual ~CListData()
    8888    {
     
    124124    m_bQuit=FALSE;
    125125    m_bCheckForTimeout=TRUE;
    126126    m_bError=FALSE;
     127    m_bUTF8 = false;
    127128}
    128129
    129130CSFtpControlSocket::~CSFtpControlSocket()
     
    154155    ASSERT(!m_Operation.nOpMode);
    155156   
    156157    ASSERT(!m_pProxyLayer);
    157    
     158
     159    m_bUTF8 = (server.nUTF8 == 1);
     160
    158161    if (!server.fwbypass)
    159162    {
    160163        int nProxyType=COptions::GetOptionVal(OPTION_PROXYTYPE);
     
    326329        if (m_Operation.nOpState==LIST_PWD)
    327330        { //Reply to PWD command
    328331            pData->realpath.SetServer(m_CurrentServer);
    329             if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
    330             {
    331                 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    332                 ResetOperation(FZ_REPLY_ERROR);
    333                 return;
     332            if (m_bUTF8) {
     333                USES_CONVERSION;
     334
     335                // convert from UTF-8 to ANSI
     336                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     337                if (len != 0)
     338                {
     339                    LPWSTR p1 = new WCHAR[len + 1];
     340                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     341                    CString tempstr = W2CT(p1);
     342                    delete [] p1;
     343                    if (tempstr=="" || !pData->realpath.SetPath(tempstr))
     344                    {
     345                        LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     346                        ResetOperation(FZ_REPLY_ERROR);
     347                        return;
     348                    }
     349                    pData->rawpwd=tempstr;
     350                }
     351                else
     352                {
     353                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     354                    ResetOperation(FZ_REPLY_ERROR);
     355                    return;
     356                }
     357            }
     358            else {
     359                if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
     360                {
     361                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     362                    ResetOperation(FZ_REPLY_ERROR);
     363                    return;
     364                }
     365                pData->rawpwd=m_Reply;
    334366            }
    335             pData->rawpwd=m_Reply;
    336367            m_pOwner->SetCurrentPath(pData->realpath);
    337368            if (pData->nListMode&FZ_LIST_USECACHE)
    338369            {
     
    363394        else if (m_Operation.nOpState==LIST_CWD)
    364395        {
    365396            pData->realpath.SetServer(m_CurrentServer);
    366             if (m_Reply == "" || !pData->realpath.SetPath(A2CT(m_Reply)))
    367             {
    368                 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    369                 ResetOperation(FZ_REPLY_ERROR);
    370                 return;
     397            if (m_bUTF8) {
     398                USES_CONVERSION;
     399
     400                // convert from UTF-8 to ANSI
     401                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     402                if (len != 0)
     403                {
     404                    LPWSTR p1 = new WCHAR[len + 1];
     405                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     406                    CString tempstr = W2CT(p1);
     407                    delete [] p1;
     408                    if (tempstr=="" || !pData->realpath.SetPath(tempstr))
     409                    {
     410                        LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     411                        ResetOperation(FZ_REPLY_ERROR);
     412                        return;
     413                    }
     414                    pData->rawpwd=tempstr;
     415                }
     416                else
     417                {
     418                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     419                    ResetOperation(FZ_REPLY_ERROR);
     420                    return;
     421                }
     422            }
     423            else {
     424                if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
     425                {
     426                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     427                    ResetOperation(FZ_REPLY_ERROR);
     428                    return;
     429                }
     430                pData->rawpwd=m_Reply;
    371431            }
    372             pData->rawpwd = m_Reply;
    373432            m_pOwner->SetCurrentPath(pData->realpath);
    374433            if (pData->nListMode&FZ_LIST_USECACHE && pData->subdir=="")
    375434            {
     
    410469        else if (m_Operation.nOpState==LIST_CWD2)
    411470        {
    412471            pData->realpath.SetServer(m_CurrentServer);
    413             if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
    414             {
    415                 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    416                 ResetOperation(FZ_REPLY_ERROR);
    417                 return;
     472            if (m_bUTF8) {
     473                USES_CONVERSION;
     474
     475                // convert from UTF-8 to ANSI
     476                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     477                if (len != 0)
     478                {
     479                    LPWSTR p1 = new WCHAR[len + 1];
     480                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     481                    CString tempstr = W2CT(p1);
     482                    delete [] p1;
     483                    if (tempstr=="" || !pData->realpath.SetPath(tempstr))
     484                    {
     485                        LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     486                        ResetOperation(FZ_REPLY_ERROR);
     487                        return;
     488                    }
     489                    pData->rawpwd=tempstr;
     490                }
     491                else
     492                {
     493                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     494                    ResetOperation(FZ_REPLY_ERROR);
     495                    return;
     496                }
     497            }
     498            else {
     499                if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
     500                {
     501                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
     502                    ResetOperation(FZ_REPLY_ERROR);
     503                    return;
     504                }
     505                pData->rawpwd=m_Reply;
    418506            }
    419             pData->rawpwd=m_Reply;
    420507            m_pOwner->SetCurrentPath(pData->realpath);
    421508            if (pData->nListMode&FZ_LIST_USECACHE)
    422509            {
     
    512599   
    513600    if (m_Operation.nOpState==LIST_INIT)
    514601    { //Initialize some variables
    515         pData = new CListData(m_CurrentServer);;
     602        pData = new CListData(m_CurrentServer, m_bUTF8);
    516603        pData->nListMode=nListMode;
    517604        pData->path=path;
    518605        pData->subdir=subdir;
     
    691778       
    692779        m_Operation.nOpMode=CSMODE_TRANSFER|(transferfile->get?CSMODE_DOWNLOAD:CSMODE_UPLOAD);
    693780
    694         pData = new CFileTransferData(m_CurrentServer);
     781        pData = new CFileTransferData(m_CurrentServer, m_bUTF8);
    695782        m_Operation.pData=pData;
    696783
    697784        //Replace invalid characters in the local filename
     
    821908            {
    822909                CServerPath path;
    823910                path.SetServer(m_CurrentServer);
    824                 if (!path.SetPath(A2CT(m_Reply)))
     911                CString tempstr;
     912                if (m_bUTF8) {
     913                    USES_CONVERSION;
     914
     915                    // convert from UTF-8 to ANSI
     916                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     917                    if (len != 0)
     918                    {
     919                        LPWSTR p1 = new WCHAR[len + 1];
     920                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     921                        tempstr = W2CT(p1);
     922                        delete [] p1;
     923                    }
     924                    else
     925                    {
     926                        tempstr = "";
     927                    }
     928                }
     929                else {
     930                    tempstr = A2CT(m_Reply);
     931                }
     932                if (!path.SetPath(tempstr))
    825933                {
    826934                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path"));
    827935                    nReplyError=FZ_REPLY_ERROR;
    828936                }
    829937                else
    830938                {
    831                     pData->rawpwd=m_Reply;
     939                    pData->rawpwd=tempstr;
    832940                    m_pOwner->SetCurrentPath(path);
    833941                    if (path!=pData->transferfile.remotepath)
    834942                        nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR;
     
    10461154            {
    10471155                CServerPath path;
    10481156                path.SetServer(m_CurrentServer);
    1049                 if (!path.SetPath(A2CT(m_Reply)))
     1157                CString tempstr;
     1158                if (m_bUTF8) {
     1159                    USES_CONVERSION;
     1160
     1161                    // convert from UTF-8 to ANSI
     1162                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     1163                    if (len != 0)
     1164                    {
     1165                        LPWSTR p1 = new WCHAR[len + 1];
     1166                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     1167                        tempstr = W2CT(p1);
     1168                        delete [] p1;
     1169                    }
     1170                    else
     1171                    {
     1172                        tempstr = "";
     1173                    }
     1174                }
     1175                else {
     1176                    tempstr = A2CT(m_Reply);
     1177                }
     1178                if (!path.SetPath(tempstr))
    10501179                {
    10511180                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path"));
    10521181                    nReplyError=FZ_REPLY_ERROR;
    10531182                }
    10541183                else
    10551184                {
    1056                     pData->rawpwd=m_Reply;
     1185                    pData->rawpwd=tempstr;
    10571186                    m_pOwner->SetCurrentPath(path);
    10581187                    if (path!=pData->transferfile.remotepath)
    10591188                        nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR;
     
    13361465            filename = pData->transferfile.remotefile;
    13371466        else
    13381467            filename = pData->transferfile.remotepath.GetPath() + pData->transferfile.remotefile;
    1339         int nLen1 = strlen(T2CA(filename)) + 1;
    1340         int nLen2 = strlen(T2CA(pData->transferfile.localfile)) + 1;
    1341         char *pCmd=new char[nLen1+nLen2+4];
    1342         strcpy(pCmd, T2CA(filename));
    1343         strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile));
    1344         memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1468        char *pCmd;
     1469        int nLen1;
     1470        int nLen2;
     1471        CString status = filename + _T(" ") + pData->transferfile.localfile;
     1472        if (pData->transferdata.bResume)
     1473            status += _T(" TRUE");
     1474        else
     1475            status += _T(" FALSE");
     1476        if (m_bUTF8) {
     1477#ifdef _UNICODE
     1478            LPCWSTR unicode_remote = T2CW(filename);
     1479            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0);
     1480            char* utf8_remote = new char[len + 1];
     1481            WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0);
     1482            LPCWSTR unicode_local = T2CW(pData->transferfile.localfile);
     1483            len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0);
     1484            char* utf8_local = new char[len + 1];
     1485            WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0);
     1486            nLen1=strlen(utf8_remote) + 1;
     1487            nLen2=strlen(utf8_local)+1;
     1488            pCmd=new char[nLen1+nLen2+4];
     1489            strcpy(pCmd, utf8_remote);
     1490            delete [] utf8_remote;
     1491            strcpy(pCmd+nLen1, utf8_local);
     1492            delete [] utf8_local;
     1493            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1494#else
     1495            LPCWSTR unicode_remote = T2CW(filename);
     1496            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0);
     1497            char* utf8_remote = new char[len + 1];
     1498            WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0);
     1499            nLen1=strlen(utf8_remote) + 1;
     1500            nLen2=strlen(T2CA(pData->transferfile.localfile))+1;
     1501            pCmd=new char[nLen1+nLen2+4];
     1502            strcpy(pCmd, utf8_remote);
     1503            delete [] utf8_remote;
     1504            strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile));
     1505            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1506#endif
     1507        }
     1508        else {
     1509#ifdef _UNICODE
     1510            LPCWSTR unicode_local = T2CW(pData->transferfile.localfile);
     1511            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0);
     1512            char* utf8_local = new char[len + 1];
     1513            WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0);
     1514            nLen1=strlen(T2CA(filename)) + 1;
     1515            nLen2=strlen(utf8_local)+1;
     1516            pCmd=new char[nLen1+nLen2+4];
     1517            strcpy(pCmd, T2CA(filename));
     1518            strcpy(pCmd+nLen1, utf8_local);
     1519            delete [] utf8_local;
     1520            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1521#else
     1522            nLen1=strlen(T2CA(filename)) + 1;
     1523            nLen2=strlen(T2CA(pData->transferfile.localfile))+1;
     1524            pCmd=new char[nLen1+nLen2+4];
     1525            strcpy(pCmd, T2CA(filename));
     1526            strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile));
     1527            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1528#endif
     1529        }
    13451530        pData->pStartTime = new CTime;
    13461531        *pData->pStartTime = CTime::GetCurrentTime();
    13471532        if (pData->transferfile.get)
    13481533        {
    1349             if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd))
     1534            if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd, status))
    13501535                bError=TRUE;
    13511536        }
    13521537        else
    1353             if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd))
     1538            if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd, status))
    13541539                bError=TRUE;
    13551540
    13561541
     
    15061691        m_Operation.nOpMode = CSMODE_RENAME;
    15071692        int nLen;
    15081693        char *pData;
     1694        CString s_oldname, s_newname;
    15091695        if (newPath.IsEmpty())
    15101696        {
    1511             nLen = _tcslen( path.GetPath() + oldName + path.GetPath() + newName) + 2;
     1697            s_oldname = path.GetPath() + oldName;
     1698            s_newname = path.GetPath() + newName;
     1699        }
     1700        else {
     1701            s_oldname = path.GetPath() + oldName;
     1702            s_newname = newPath.GetPath() + newName;
     1703        }
     1704        CString status = s_oldname + _T(" ") + s_newname;
     1705        if (m_bUTF8) {
     1706            LPCWSTR uni_oldname = T2CW(s_oldname);
     1707            int len = WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, 0, 0, 0, 0);
     1708            char* utf8_oldname = new char[len + 1];
     1709            WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, utf8_oldname, len + 1, 0, 0);
     1710            LPCWSTR uni_newname = T2CW(s_newname);
     1711            len = WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, 0, 0, 0, 0);
     1712            char* utf8_newname = new char[len + 1];
     1713            WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, utf8_newname, len + 1, 0, 0);
     1714            nLen = strlen(utf8_oldname) + strlen(utf8_newname) + 2;
    15121715            pData = new char[nLen];
    1513             strcpy(pData, T2CA(path.GetPath() + oldName));
    1514             strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(path.GetPath() + newName));
     1716            strcpy(pData, utf8_oldname);
     1717            strcpy(pData + strlen(utf8_oldname) + 1, utf8_newname);
     1718            delete [] utf8_oldname;
     1719            delete [] utf8_newname;
    15151720        }
    1516         else
    1517         {
    1518             nLen = _tcslen( path.GetPath() + oldName + newPath.GetPath() + newName) + 2;
     1721        else {
     1722            nLen = _tcslen( s_oldname + s_newname) + 2;
    15191723            pData = new char[nLen];
    1520             strcpy(pData, T2CA(path.GetPath() + oldName));
    1521             strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(newPath.GetPath() + newName));
     1724            strcpy(pData, T2CA(s_oldname));
     1725            strcpy(pData + _tcslen(s_oldname) + 1, T2CA(s_newname));
    15221726        }
    1523         if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData))
     1727        if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData, status))
    15241728        {
    15251729            delete [] pData;
    15261730            DoClose();
     
    21942398            while (p=strstr(str, "\n"))
    21952399            {
    21962400                *p = 0;
    2197                 ShowStatus(str, 3);
     2401                if (m_bUTF8) {
     2402                    USES_CONVERSION;
     2403
     2404                    // convert from UTF-8 to ANSI
     2405                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0);
     2406                    if (len != 0)
     2407                    {
     2408                        LPWSTR p1 = new WCHAR[len + 1];
     2409                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2);
     2410                        CString tempstr = W2CT(p1);
     2411                        delete [] p1;
     2412                        ShowStatus(tempstr, 3);
     2413                    }
     2414                    else
     2415                        ShowStatus(str, 3);
     2416                }
     2417                else
     2418                    ShowStatus(str, 3);
    21982419                str = p+1;
    21992420            }
    2200             ShowStatus(str, 3);
     2421            if (m_bUTF8) {
     2422                USES_CONVERSION;
     2423
     2424                // convert from UTF-8 to ANSI
     2425                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0);
     2426                if (len != 0)
     2427                {
     2428                    LPWSTR p1 = new WCHAR[len + 1];
     2429                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2);
     2430                    CString tempstr = W2CT(p1);
     2431                    delete [] p1;
     2432                    ShowStatus(tempstr, 3);
     2433                }
     2434                else
     2435                    ShowStatus(str, 3);
     2436            }
     2437            else
     2438                ShowStatus(str, 3);
    22012439        }
    22022440        break;
    22032441    case SFTP_DATAID_CTS_CRITICALERROR:
     
    22422480            ResetOperation(FZ_REPLY_ERROR);
    22432481        else
    22442482        {
    2245             ShowStatus((char *)pData, 3);
     2483            if (m_bUTF8) {
     2484                USES_CONVERSION;
     2485
     2486                // convert from UTF-8 to ANSI
     2487                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1, NULL, 0);
     2488                if (len != 0)
     2489                {
     2490                    LPWSTR p1 = new WCHAR[len + 1];
     2491                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1 , (LPWSTR)p1, len*2);
     2492                    CString tempstr = W2CT(p1);
     2493                    delete [] p1;
     2494                    ShowStatus(tempstr, 3);
     2495                }
     2496                else
     2497                    ShowStatus((char *)pData, 3);
     2498            }
     2499            else
     2500                ShowStatus((char *)pData, 3);
    22462501            ProcessReply();
    22472502        }
    22482503        break;
     
    29213176    USES_CONVERSION;
    29223177    m_Operation.nOpMode=CSMODE_CHMOD;
    29233178    CString str;
     3179    CString status;
     3180    int nLen;
     3181    char *pData;
    29243182    str.Format( _T("%d %s%s"), nValue, path.GetPath(), filename);
    2925     int nLen = strlen(T2CA(str)) + 1;
    2926     char *pData=new char[nLen];
    2927     strcpy(pData, T2CA(str));
    2928     int pos(str.Find( _T(" ") ));
    2929     ASSERT(pos!=-1);
    2930     pData[pos]=0;
    2931     if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData))
     3183    status = str;
     3184    if (m_bUTF8) {
     3185        LPCWSTR unicode = T2CW(str);
     3186        int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
     3187        char* utf8 = new char[len + 1];
     3188        WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
     3189        nLen=strlen(utf8)+1;
     3190        pData=new char[nLen];
     3191        strcpy(pData, utf8);
     3192        int pos(str.Find( _T(" ") ));
     3193        ASSERT(pos!=-1);
     3194        pData[pos]=0;
     3195    }
     3196    else {
     3197        nLen=strlen(T2CA(str))+1;
     3198        pData=new char[nLen];
     3199        strcpy(pData, T2CA(str));
     3200        int pos(str.Find( _T(" ") ));
     3201        ASSERT(pos!=-1);
     3202        pData[pos]=0;
     3203    }
     3204    if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData, status))
    29323205        DoClose();
    29333206    delete [] pData;
    29343207}
  • SftpControlSocket.h

    diff -Nur source/SftpControlSocket.h source.patch/SftpControlSocket.h
    old new  
    3737class CSFtpControlSocket : public CControlSocket
    3838{
    3939public:
     40    bool m_bUTF8;
    4041    BOOL m_bError;
    4142    void OnClientError(int nErrorCode);
    4243    int OnClientRequest(int nId, int &nDataLength, LPVOID pData);