Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.2k views
in .NET FTP by (280 points)
Hi there, I've tried searching the forums for my solution, but I can't seem to find out whats wrong.

I've changed the encoding for the FTPConnection:

FTPConnection.DataEncoding = System.Text.Encoding.UTF8

I've tried:

FTPConnection.DataEncoding = System.Text.Encoding.Unicode
FTPConnection.DataEncoding = System.Text.Encoding.GetEncoding("Windows-1252")
FTPConnection.DataEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1")

With no success, the filenames have Latin characters in them and on the server the letters are there, but when I use:

For Each file As EnterpriseDT.Net.Ftp.FTPFile In FTPConnection.GetFileInfos()
Debug.Print(file.Name)
Next

The letters are missing, like it just strips them from the name completely. Why isn't the encoding holding? I've connected with Filezilla Client and the directory listing from the server is fine, as Filezilla Client shows them. It just seems that setting the property for FTPConnection.DataEncoding isn't sticking.

Any ideas?

6 Answers

0 votes
by (162k points)
Do you get the same result using GetFiles()?
0 votes
by (280 points)
Thank you for your quick reply.

Yes, sorry for not mentioning it in my original post, I have tried GetFiles:

For Each s As String in FTPConnection.GetFiles()
Debug.Print(s)
Next

Same results.

I even enabled debug at level all and the debug information strips the letters also.
0 votes
by (280 points)
This is the debug with no command encoding, notice the "Reading ASCII listing data"

DEBUG [FTPConnection] 11 Aug 2009 15:32:30.468 : Set LocalDirectory='<removed_path>'
DEBUG [HostNameResolver] 11 Aug 2009 15:32:30.708 : mydomain.net resolved to x.x.x.x
DEBUG [FTPClient] 11 Aug 2009 15:32:30.708 : Connecting to x.x.x.x:21
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:30.819 : Setting socket timeout=120000
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:30.821 : Command encoding=System.Text.ASCIIEncoding
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:30.826 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:30.923 : 220-FileZilla Server version 0.9.32 beta
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.718 : 220-written by Tim Kosse (Tim.Kosse@gmx.de)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.718 : 220 Please visit http://sourceforge.net/projects/filezilla/
DEBUG [FTPConnection] 11 Aug 2009 15:32:31.721 : Connected to mydomain.net
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.725 : ---> USER user
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.833 : 331 Password required for user
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.835 : ---> PASS ********
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.941 : 230 Logged on
DEBUG [FTPConnection] 11 Aug 2009 15:32:31.941 : Successfully logged in
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:31.943 : ---> TYPE I
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.045 : 200 Type set to I
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.046 : ---> PWD
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.155 : 257 "/" is current directory.
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.157 : ---> TYPE I
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.261 : 200 Type set to I
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.263 : ---> CWD /
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.377 : 250 CWD successful. "/" is current directory.
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.377 : ---> PWD
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.482 : 257 "/" is current directory.
DEBUG [FTPConnection] 11 Aug 2009 15:32:32.485 : Listing directory ''
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.492 : ---> PASV
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.603 : 227 Entering Passive Mode (x,x,x,x,19,150)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.604 : Server supplied address=x.x.x.x
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.604 : Server supplied port=5014
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.604 : Substituting server supplied IP (x.x.x.x) with remote host IP (x.x.x.x)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.605 : NewPassiveDataSocket(x.x.x.x,5014)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.711 : ---> NLST
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.822 : 150 Connection accepted
DEBUG [FTPClient] 11 Aug 2009 15:32:32.824 : Reading ASCII listing data
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->ayer_cuando_te_v-L.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->baila_mi_corazn-B.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->besos_fciles_love_show-S.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->cancin_de_adis-C.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->conctate-O.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:32.826 : -->mame_-T.mpg
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.827 : 226 Transfer OK
DEBUG [FTPClient] 11 Aug 2009 15:32:32.827 : Found 6 listing lines
DEBUG [FTPConnection] 11 Aug 2009 15:32:32.827 : Listed directory ''
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.836 : ---> SYST
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.944 : 215 UNIX emulated by FileZilla
DEBUG [FTPFileFactory] 11 Aug 2009 15:32:32.946 : Selected UNIX parser
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:32.947 : ---> PWD
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.050 : 257 "/" is current directory.
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.051 : ---> PASV
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.159 : 227 Entering Passive Mode (x,x,x,x,19,151)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.159 : Server supplied address=x.x.x.x
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.159 : Server supplied port=5015
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.159 : Substituting server supplied IP (x.x.x.x) with remote host IP (x.x.x.x)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.159 : NewPassiveDataSocket(x.x.x.x,5015)
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.266 : ---> LIST
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.375 : 150 Connection accepted
DEBUG [FTPClient] 11 Aug 2009 15:32:33.375 : Reading ASCII listing data
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 152973312 Jul 03 2009 ayer_cuando_te_v-L.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 130695168 Jul 03 2009 baila_mi_corazn-B.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 197271552 Jul 03 2009 besos_fciles_love_show-S.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 212199424 Jul 03 2009 cancin_de_adis-C.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 156979200 Jul 03 2009 conctate-O.mpg
DEBUG [FTPClient] 11 Aug 2009 15:32:33.376 : -->-rw-r--r-- 1 ftp ftp 168175616 Jul 03 2009 mame_-T.mpg
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.378 : 226 Transfer OK
DEBUG [FTPClient] 11 Aug 2009 15:32:33.378 : Found 6 listing lines
DEBUG [FTPFileFactory] 11 Aug 2009 15:32:33.380 : Parse() called using culture: Invariant Language (Invariant Country)
DEBUG [FTPFileFactory] 11 Aug 2009 15:32:33.384 : Confirmed format UNIX
DEBUG [FTPFileFactory] 11 Aug 2009 15:32:33.399 : Defaulting to Unix parsing
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.399 : ---> QUIT
DEBUG [FTPControlSocket] 11 Aug 2009 15:32:33.504 : 221 Goodbye


This is with ISO-8859-1 command encoding, notice the characters are there, but I'm stumped as why some have an extra character after it:

[quote]
DEBUG [FTPConnection] 11 Aug 2009 15:43:50.258 : Set LocalDirectory='<removed_path>'
DEBUG [HostNameResolver] 11 Aug 2009 15:43:50.275 : mydomain.net resolved to x.x.x.x
DEBUG [FTPClient] 11 Aug 2009 15:43:50.276 : Connecting to x.x.x.x:21
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.384 : Setting socket timeout=120000
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.386 : Command encoding=System.Text.Latin1Encoding
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.391 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.491 : 220-FileZilla Server version 0.9.32 beta
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.780 : 220-written by Tim Kosse (Tim.Kosse@gmx.de)
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.780 : 220 Please visit http://sourceforge.net/projects/filezilla/
DEBUG [FTPConnection] 11 Aug 2009 15:43:50.783 : Connected to mydomain.net
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.788 : ---> USER user
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.892 : 331 Password required for user
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.893 : ---> PASS ********
DEBUG [FTPControlSocket] 11 Aug 2009 15:43:50.997 : 230 Logged on
DEBUG [FTPConnection] 11 Aug 2009 1
0 votes
by (162k points)
Any luck with this? Quite a lot of people use the encodings, I'm a bit puzzled as to why it doesn't work for you ...
0 votes
by (280 points)
Any luck with this? Quite a lot of people use the encodings, I'm a bit puzzled as to why it doesn't work for you ...


No luck, haven't tried anything since I posted the debug log. Was hoping to get a reply with something I'm doing wrong that you saw in the log. I'm also puzzled. I'll try some very basic tests today and see if I can come up with something. Either way, I'll post my findings.
0 votes
by (280 points)
Ok, so the problem was still encoding, I just had to do some extra steps in my code:

First off, I set the command encoding:

FTPConnection.CommandEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1")


Then during my GetFiles I do:

Dim fileName As String = Text.Encoding.UTF8.GetString(Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(file.Name))
Debug.Print(fileName)

Dim fileRaw As String = Text.Encoding.UTF8.GetString(Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(file.Raw))
Debug.Print(fileRaw)


That fixed it for me.

Categories

...