Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FTP codepage support #482

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/filezilla/FtpControlSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,22 +1479,22 @@ BOOL CFtpControlSocket::Send(CString str)
ShowStatus(str, FZ_LOG_COMMAND);
str += L"\r\n";
int res = 0;
if (m_bUTF8)
if (m_bUTF8 || m_nCodePage /* unlike WinSCP, NetBox works with code pages*/)
{
LPCWSTR unicode = T2CW(str);
int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0);
int len = WideCharToMultiByte(m_bUTF8 ? CP_UTF8 : m_nCodePage, 0, unicode, -1, 0, 0, 0, 0);
if (!len)
{
ShowStatus(IDS_ERRORMSG_CANTSENDCOMMAND, FZ_LOG_ERROR);
DoClose();
return FALSE;
}
char *utf8 = nb::chcalloc(len + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0);
WideCharToMultiByte(m_bUTF8 ? CP_UTF8 : m_nCodePage, 0, unicode, -1, utf8, len + 1, 0, 0);

size_t sendLen = nb::safe_strlen(utf8);
if (!m_awaitsReply && !m_sendBuffer)
res = CAsyncSocketEx::Send(utf8, (int)nb::safe_strlen(utf8));
res = CAsyncSocketEx::Send(utf8, (int)nb::safe_strlen(utf8), 0, m_bUTF8 ? 0 : m_CurrentServer.iDupFF);
else
res = -2;
if ((res == SOCKET_ERROR && GetLastError() != WSAEWOULDBLOCK) || !res)
Expand Down Expand Up @@ -1548,7 +1548,7 @@ BOOL CFtpControlSocket::Send(CString str)
if (!m_sendBuffer)
{
m_sendBuffer = nb::chcalloc(sendLen - res);
nbstr_memcpy(m_sendBuffer, lpszAsciiSend, sendLen - res);
nbstr_memcpy(m_sendBuffer, lpszAsciiSend + res, sendLen - res);
m_sendBufferLen = sendLen - res;
}
else
Expand Down