-
July 9th, 2008, 01:55 PM
#1
CInternetSession / CFtpConnection + unicode filenames
Hi all,
I am having some problems retrieving files with unicode characters inside the filename.
For example, one of the files contains the character ğ, but when I try to request the file, the FTP server shows that a file with a "normal" g is requested instead of the special file character. Therefore, the FTP will return that the file does not exist.
I am using CFtpConnection to receive the files.
Any ideas how to fix this?
Best regards,
-
July 9th, 2008, 02:23 PM
#2
Re: CInternetSession / CFtpConnection + unicode filenames
Found the problem! I need to convert to a "safe" filename first. Here is some example code:
Code:
CString CFtpFileObject::ConvertToSafeFileName(CString sFileName)
{
// Declare variables
long lLength = 0, lBufferSize = 0, lResult = 0;
CString sResult = _T("");
// Get the length
lLength = sFileName.GetLength();
// Check if we have a valid string
if (lLength == 0)
{
// No, just return the original one
return sFileName;
}
//Set buffer for longest possible string.
lBufferSize = lLength * 3 + 1;
char * pBytUtf8 = new char[lBufferSize];
// Translate using code page 65001(UTF-8).
lResult = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)sFileName, lLength,
pBytUtf8, lBufferSize, NULL, 0);
// Clear buffer
pBytUtf8[lResult] = NULL;
// Return result
return CString(pBytUtf8);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|