Can you tell me how to encode the File data for the FTP connector when using the FTP method 'Upload file (STOR)’?
It seems that the connector uses the UFT-16 Little Endian although the source for the data comes from a VARCHAR.
Can you tell me how to encode the File data for the FTP connector when using the FTP method 'Upload file (STOR)’?
It seems that the connector uses the UFT-16 Little Endian although the source for the data comes from a VARCHAR.
Best answer by Vincent Doppenberg
Hello Onno,
The key question here is where the XML comes from.
Are you reading an existing XML file with a Read file connector and then uploading it with an FTP connector? If so, then the XML file should already be encoded correctly and reading it into a VARBINARY process variable and then uploading it with the FTP connector will not alter the encoding in any way.
The other option is that there is no existing XML file, but you have a text representation of the XML. For example, an XML or VARCHAR column in the database or a FOR PATH query that produces XML for you. If this is the case, then it’s a bit more tricky because by default VARCHAR uses the ANSI encoding (Windows code page 1252) and NVARCHAR uses the UTF-16 encoding in SQL Server. As of SQL Server 2019 however, there is support for UTF-8 encoding via collations. So you can actually perform UTF-16 NVARCHAR conversions to UTF-8 VARCHAR and then convert to VARBINARY to get a UTF-8 encoded binary representation of the XML text.
CREATE TABLE #temp_utf8
(
col VARCHAR(MAX) COLLATE LATIN1_GENERAL_100_CI_AS_SC_UTF8
)
INSERT INTO #temp_utf8 VALUES(N'谢谢')
SELECT CAST(t1.col AS VARBINARY(200))
FROM #temp_utf8 t1
I have just tested this myself and the example correctly returns the UTF-8 encoded bytes for those characters.
I hope this helps, please let me know if you have additional questions.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.