Ticket #1467: filezilla_sftp_utf8_2212c.patch

File filezilla_sftp_utf8_2212c.patch, 23.7 KB (added by tommywu, 19 years ago)

allow use force UTF8 option in sftp mode (for 2.2.12c)

  • 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  
    2828#include "SFtpCommandIDs.h"
    2929#include "FtpListResult.h"
    3030#include "FileExistsDlg.h"
     31#include "misc/utf8.h"
    3132
    3233#ifdef _DEBUG
    3334#undef THIS_FILE
     
    3940class CSFtpControlSocket::CFileTransferData : public CSFtpControlSocket::t_operation::COpData
    4041{
    4142public:
    42     CFileTransferData(t_server server)
     43    CFileTransferData(t_server server, bool *pbUTF8)
    4344    {
    4445        pDirectoryListing=0;
    4546        nWaitNextOpState=0;
     
    5051        transferdata.nTransferStart=0;
    5152        pStartTime=0;
    5253        bUseAbsolutePaths = FALSE;
    53         pParser = new CFtpListResult(server);
     54        pParser = new CFtpListResult(server, pbUTF8);
    5455    };
    5556    virtual ~CFileTransferData()
    5657    {
     
    7980class CSFtpControlSocket::CListData:public CSFtpControlSocket::t_operation::COpData
    8081{
    8182public:
    82     CListData(t_server server)
     83    CListData(t_server server, bool *pbUTF8)
    8384    {
    8485        pDirectoryListing=0;
    85         pParser = new CFtpListResult(server);
     86        pParser = new CFtpListResult(server, pbUTF8);
    8687    }
    8788    virtual ~CListData()
    8889    {
     
    124125    m_bQuit=FALSE;
    125126    m_bCheckForTimeout=TRUE;
    126127    m_bError=FALSE;
     128    m_bUTF8 = false;
    127129}
    128130
    129131CSFtpControlSocket::~CSFtpControlSocket()
     
    154156    ASSERT(!m_Operation.nOpMode);
    155157   
    156158    ASSERT(!m_pProxyLayer);
    157    
     159
     160    m_bUTF8 = (server.nUTF8 == 1);
     161
    158162    if (!server.fwbypass)
    159163    {
    160164        int nProxyType=COptions::GetOptionVal(OPTION_PROXYTYPE);
     
    326330        if (m_Operation.nOpState==LIST_PWD)
    327331        { //Reply to PWD command
    328332            pData->realpath.SetServer(m_CurrentServer);
    329             if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
     333            CString tempstr;
     334            if (m_bUTF8) {
     335                USES_CONVERSION;
     336
     337                LPCSTR utf8 = (LPCSTR)m_Reply;
     338                if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) {
     339                    tempstr = A2CT(m_Reply);
     340                }
     341                else  {
     342                    // convert from UTF-8 to ANSI
     343                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     344                    if (len != 0)
     345                    {
     346                        LPWSTR p1 = new WCHAR[len + 1];
     347                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     348                        tempstr = W2CT(p1);
     349                        delete [] p1;
     350                    }
     351                    else {
     352                        tempstr = A2CT(m_Reply);
     353                    }
     354                }
     355            }
     356            else {
     357                tempstr = A2CT(m_Reply);
     358            }
     359            if (tempstr=="" || !pData->realpath.SetPath(tempstr))
    330360            {
    331361                LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    332362                ResetOperation(FZ_REPLY_ERROR);
    333363                return;
    334364            }
    335             pData->rawpwd=m_Reply;
     365            pData->rawpwd=tempstr;
    336366            m_pOwner->SetCurrentPath(pData->realpath);
    337367            if (pData->nListMode&FZ_LIST_USECACHE)
    338368            {
     
    363393        else if (m_Operation.nOpState==LIST_CWD)
    364394        {
    365395            pData->realpath.SetServer(m_CurrentServer);
    366             if (m_Reply == "" || !pData->realpath.SetPath(A2CT(m_Reply)))
     396            CString tempstr;
     397            if (m_bUTF8) {
     398                USES_CONVERSION;
     399
     400                LPCSTR utf8 = (LPCSTR)m_Reply;
     401                if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) {
     402                    tempstr = A2CT(m_Reply);
     403                }
     404                else  {
     405                    // convert from UTF-8 to ANSI
     406                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     407                    if (len != 0)
     408                    {
     409                        LPWSTR p1 = new WCHAR[len + 1];
     410                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     411                        tempstr = W2CT(p1);
     412                        delete [] p1;
     413                    }
     414                    else {
     415                        tempstr = A2CT(m_Reply);
     416                    }
     417                }
     418            }
     419            else {
     420                tempstr = A2CT(m_Reply);
     421            }
     422            if (tempstr=="" || !pData->realpath.SetPath(tempstr))
    367423            {
    368424                LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    369425                ResetOperation(FZ_REPLY_ERROR);
    370426                return;
    371427            }
    372             pData->rawpwd = m_Reply;
     428            pData->rawpwd=tempstr;
    373429            m_pOwner->SetCurrentPath(pData->realpath);
    374430            if (pData->nListMode&FZ_LIST_USECACHE && pData->subdir=="")
    375431            {
     
    410466        else if (m_Operation.nOpState==LIST_CWD2)
    411467        {
    412468            pData->realpath.SetServer(m_CurrentServer);
    413             if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply)))
     469            CString tempstr;
     470            if (m_bUTF8) {
     471                USES_CONVERSION;
     472
     473                LPCSTR utf8 = (LPCSTR)m_Reply;
     474                if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) {
     475                    tempstr = A2CT(m_Reply);
     476                }
     477                else  {
     478                    // convert from UTF-8 to ANSI
     479                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     480                    if (len != 0)
     481                    {
     482                        LPWSTR p1 = new WCHAR[len + 1];
     483                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     484                        tempstr = W2CT(p1);
     485                        delete [] p1;
     486                    }
     487                    else {
     488                        tempstr = A2CT(m_Reply);
     489                    }
     490                }
     491            }
     492            else {
     493                tempstr = A2CT(m_Reply);
     494            }
     495            if (tempstr=="" || !pData->realpath.SetPath(tempstr))
    414496            {
    415497                LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") );
    416498                ResetOperation(FZ_REPLY_ERROR);
    417499                return;
    418500            }
    419             pData->rawpwd=m_Reply;
     501            pData->rawpwd=tempstr;
    420502            m_pOwner->SetCurrentPath(pData->realpath);
    421503            if (pData->nListMode&FZ_LIST_USECACHE)
    422504            {
     
    512594   
    513595    if (m_Operation.nOpState==LIST_INIT)
    514596    { //Initialize some variables
    515         pData = new CListData(m_CurrentServer);;
     597        pData = new CListData(m_CurrentServer, &m_bUTF8);
     598        pData->pParser->InitLog(this);
    516599        pData->nListMode=nListMode;
    517600        pData->path=path;
    518601        pData->subdir=subdir;
     
    691774       
    692775        m_Operation.nOpMode=CSMODE_TRANSFER|(transferfile->get?CSMODE_DOWNLOAD:CSMODE_UPLOAD);
    693776
    694         pData = new CFileTransferData(m_CurrentServer);
     777        pData = new CFileTransferData(m_CurrentServer, &m_bUTF8);
     778        pData->pParser->InitLog(this);
    695779        m_Operation.pData=pData;
    696780
    697781        //Replace invalid characters in the local filename
     
    821905            {
    822906                CServerPath path;
    823907                path.SetServer(m_CurrentServer);
    824                 if (!path.SetPath(A2CT(m_Reply)))
     908                CString tempstr;
     909                if (m_bUTF8) {
     910                    USES_CONVERSION;
     911
     912                    LPCSTR utf8 = (LPCSTR)m_Reply;
     913                    if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) {
     914                        tempstr = A2CT(m_Reply);
     915                    }
     916                    else  {
     917                        // convert from UTF-8 to ANSI
     918                        int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     919                        if (len != 0)
     920                        {
     921                            LPWSTR p1 = new WCHAR[len + 1];
     922                            MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     923                            tempstr = W2CT(p1);
     924                            delete [] p1;
     925                        }
     926                        else
     927                        {
     928                            tempstr = A2CT(m_Reply);
     929                        }
     930                    }
     931                }
     932                else {
     933                    tempstr = A2CT(m_Reply);
     934                }
     935                if (!path.SetPath(tempstr))
    825936                {
    826937                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path"));
    827938                    nReplyError=FZ_REPLY_ERROR;
    828939                }
    829940                else
    830941                {
    831                     pData->rawpwd=m_Reply;
     942                    pData->rawpwd=tempstr;
    832943                    m_pOwner->SetCurrentPath(path);
    833944                    if (path!=pData->transferfile.remotepath)
    834945                        nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR;
     
    10461157            {
    10471158                CServerPath path;
    10481159                path.SetServer(m_CurrentServer);
    1049                 if (!path.SetPath(A2CT(m_Reply)))
     1160                CString tempstr;
     1161                if (m_bUTF8) {
     1162                    USES_CONVERSION;
     1163
     1164                    LPCSTR utf8 = (LPCSTR)m_Reply;
     1165                    if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) {
     1166                        tempstr = A2CT(m_Reply);
     1167                    }
     1168                    else  {
     1169                        // convert from UTF-8 to ANSI
     1170                        int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0);
     1171                        if (len != 0)
     1172                        {
     1173                            LPWSTR p1 = new WCHAR[len + 1];
     1174                            MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2);
     1175                            tempstr = W2CT(p1);
     1176                            delete [] p1;
     1177                        }
     1178                        else
     1179                        {
     1180                            tempstr = A2CT(m_Reply);
     1181                        }
     1182                    }
     1183                }
     1184                else {
     1185                    tempstr = A2CT(m_Reply);
     1186                }
     1187                if (!path.SetPath(tempstr))
    10501188                {
    10511189                    LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path"));
    10521190                    nReplyError=FZ_REPLY_ERROR;
    10531191                }
    10541192                else
    10551193                {
    1056                     pData->rawpwd=m_Reply;
     1194                    pData->rawpwd=tempstr;
    10571195                    m_pOwner->SetCurrentPath(path);
    10581196                    if (path!=pData->transferfile.remotepath)
    10591197                        nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR;
     
    13361474            filename = pData->transferfile.remotefile;
    13371475        else
    13381476            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);
     1477        char *pCmd;
     1478        int nLen1;
     1479        int nLen2;
     1480        CString status = filename + _T(" ") + pData->transferfile.localfile;
     1481        if (pData->transferdata.bResume)
     1482            status += _T(" TRUE");
     1483        else
     1484            status += _T(" FALSE");
     1485        if (m_bUTF8) {
     1486#ifdef _UNICODE
     1487            // convert unicode to UTF-8
     1488            LPCWSTR unicode_remote = T2CW(filename);
     1489            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0);
     1490            char* utf8_remote = new char[len + 1];
     1491            WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0);
     1492            LPCWSTR unicode_local = T2CW(pData->transferfile.localfile);
     1493            len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0);
     1494            char* utf8_local = new char[len + 1];
     1495            WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0);
     1496            nLen1=strlen(utf8_remote) + 1;
     1497            nLen2=strlen(utf8_local)+1;
     1498            pCmd=new char[nLen1+nLen2+4];
     1499            strcpy(pCmd, utf8_remote);
     1500            delete [] utf8_remote;
     1501            strcpy(pCmd+nLen1, utf8_local);
     1502            delete [] utf8_local;
     1503            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1504#else
     1505            // convert ANSI to UTF-8
     1506            LPCWSTR unicode_remote = T2CW(filename);
     1507            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0);
     1508            char* utf8_remote = new char[len + 1];
     1509            WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0);
     1510            nLen1=strlen(utf8_remote) + 1;
     1511            nLen2=strlen(T2CA(pData->transferfile.localfile))+1;
     1512            pCmd=new char[nLen1+nLen2+4];
     1513            strcpy(pCmd, utf8_remote);
     1514            delete [] utf8_remote;
     1515            strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile));
     1516            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1517#endif
     1518        }
     1519        else {
     1520#ifdef _UNICODE
     1521            // convert unicode to UTF-8
     1522            LPCWSTR unicode_local = T2CW(pData->transferfile.localfile);
     1523            int len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0);
     1524            char* utf8_local = new char[len + 1];
     1525            WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0);
     1526            nLen1=strlen(T2CA(filename)) + 1;
     1527            nLen2=strlen(utf8_local)+1;
     1528            pCmd=new char[nLen1+nLen2+4];
     1529            strcpy(pCmd, T2CA(filename));
     1530            strcpy(pCmd+nLen1, utf8_local);
     1531            delete [] utf8_local;
     1532            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1533#else
     1534            nLen1=strlen(T2CA(filename)) + 1;
     1535            nLen2=strlen(T2CA(pData->transferfile.localfile))+1;
     1536            pCmd=new char[nLen1+nLen2+4];
     1537            strcpy(pCmd, T2CA(filename));
     1538            strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile));
     1539            memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4);
     1540#endif
     1541        }
    13451542        pData->pStartTime = new CTime;
    13461543        *pData->pStartTime = CTime::GetCurrentTime();
    13471544        if (pData->transferfile.get)
    13481545        {
    1349             if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd))
     1546            if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd, status))
    13501547                bError=TRUE;
    13511548        }
    13521549        else
    1353             if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd))
     1550            if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd, status))
    13541551                bError=TRUE;
    13551552
    13561553
     
    15061703        m_Operation.nOpMode = CSMODE_RENAME;
    15071704        int nLen;
    15081705        char *pData;
     1706        CString s_oldname, s_newname;
    15091707        if (newPath.IsEmpty())
    15101708        {
    1511             nLen = _tcslen( path.GetPath() + oldName + path.GetPath() + newName) + 2;
     1709            s_oldname = path.GetPath() + oldName;
     1710            s_newname = path.GetPath() + newName;
     1711        }
     1712        else {
     1713            s_oldname = path.GetPath() + oldName;
     1714            s_newname = newPath.GetPath() + newName;
     1715        }
     1716        CString status = s_oldname + _T(" ") + s_newname;
     1717        if (m_bUTF8) {
     1718            LPCWSTR uni_oldname = T2CW(s_oldname);
     1719            int len = WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, 0, 0, 0, 0);
     1720            char* utf8_oldname = new char[len + 1];
     1721            WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, utf8_oldname, len + 1, 0, 0);
     1722            LPCWSTR uni_newname = T2CW(s_newname);
     1723            len = WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, 0, 0, 0, 0);
     1724            char* utf8_newname = new char[len + 1];
     1725            WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, utf8_newname, len + 1, 0, 0);
     1726            nLen = strlen(utf8_oldname) + strlen(utf8_newname) + 2;
    15121727            pData = new char[nLen];
    1513             strcpy(pData, T2CA(path.GetPath() + oldName));
    1514             strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(path.GetPath() + newName));
     1728            strcpy(pData, utf8_oldname);
     1729            strcpy(pData + strlen(utf8_oldname) + 1, utf8_newname);
     1730            delete [] utf8_oldname;
     1731            delete [] utf8_newname;
    15151732        }
    1516         else
    1517         {
    1518             nLen = _tcslen( path.GetPath() + oldName + newPath.GetPath() + newName) + 2;
     1733        else {
     1734            nLen = _tcslen( s_oldname + s_newname) + 2;
    15191735            pData = new char[nLen];
    1520             strcpy(pData, T2CA(path.GetPath() + oldName));
    1521             strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(newPath.GetPath() + newName));
     1736            strcpy(pData, T2CA(s_oldname));
     1737            strcpy(pData + _tcslen(s_oldname) + 1, T2CA(s_newname));
    15221738        }
    1523         if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData))
     1739        if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData, status))
    15241740        {
    15251741            delete [] pData;
    15261742            DoClose();
     
    21942410            while (p=strstr(str, "\n"))
    21952411            {
    21962412                *p = 0;
    2197                 ShowStatus(str, 3);
     2413                if (m_bUTF8) {
     2414                    USES_CONVERSION;
     2415
     2416                    // convert from UTF-8 to ANSI
     2417                    int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0);
     2418                    if (len != 0)
     2419                    {
     2420                        LPWSTR p1 = new WCHAR[len + 1];
     2421                        MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2);
     2422                        CString tempstr = W2CT(p1);
     2423                        delete [] p1;
     2424                        ShowStatus(tempstr, 3);
     2425                    }
     2426                    else
     2427                        ShowStatus(str, 3);
     2428                }
     2429                else
     2430                    ShowStatus(str, 3);
    21982431                str = p+1;
    21992432            }
    2200             ShowStatus(str, 3);
     2433            if (m_bUTF8) {
     2434                USES_CONVERSION;
     2435
     2436                // convert from UTF-8 to ANSI
     2437                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0);
     2438                if (len != 0)
     2439                {
     2440                    LPWSTR p1 = new WCHAR[len + 1];
     2441                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2);
     2442                    CString tempstr = W2CT(p1);
     2443                    delete [] p1;
     2444                    ShowStatus(tempstr, 3);
     2445                }
     2446                else
     2447                    ShowStatus(str, 3);
     2448            }
     2449            else
     2450                ShowStatus(str, 3);
    22012451        }
    22022452        break;
    22032453    case SFTP_DATAID_CTS_CRITICALERROR:
     
    22422492            ResetOperation(FZ_REPLY_ERROR);
    22432493        else
    22442494        {
    2245             ShowStatus((char *)pData, 3);
     2495            if (m_bUTF8) {
     2496                USES_CONVERSION;
     2497
     2498                // convert from UTF-8 to ANSI
     2499                int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1, NULL, 0);
     2500                if (len != 0)
     2501                {
     2502                    LPWSTR p1 = new WCHAR[len + 1];
     2503                    MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1 , (LPWSTR)p1, len*2);
     2504                    CString tempstr = W2CT(p1);
     2505                    delete [] p1;
     2506                    ShowStatus(tempstr, 3);
     2507                }
     2508                else
     2509                    ShowStatus((char *)pData, 3);
     2510            }
     2511            else
     2512                ShowStatus((char *)pData, 3);
    22462513            ProcessReply();
    22472514        }
    22482515        break;
     
    29213188    USES_CONVERSION;
    29223189    m_Operation.nOpMode=CSMODE_CHMOD;
    29233190    CString str;
     3191    CString status;
     3192    int nLen;
     3193    char *pData;
    29243194    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))
     3195    status = str;
     3196    if (m_bUTF8) {
     3197        LPCWSTR unicode = T2CW(str);
     3198        int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
     3199        char* utf8 = new char[len + 1];
     3200        WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
     3201        nLen=strlen(utf8)+1;
     3202        pData=new char[nLen];
     3203        strcpy(pData, utf8);
     3204        int pos(str.Find( _T(" ") ));
     3205        ASSERT(pos!=-1);
     3206        pData[pos]=0;
     3207    }
     3208    else {
     3209        nLen=strlen(T2CA(str))+1;
     3210        pData=new char[nLen];
     3211        strcpy(pData, T2CA(str));
     3212        int pos(str.Find( _T(" ") ));
     3213        ASSERT(pos!=-1);
     3214        pData[pos]=0;
     3215    }
     3216    if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData, status))
    29323217        DoClose();
    29333218    delete [] pData;
    29343219}
  • 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);