Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.4k views
in Java FTP by
FTPClient ftp = new FTPClient(host);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
{
ftp.get(files[i]);
}

com.enterprisedt.net.ftp.FTPException: Can't open fil?n?me.txt: No such file or directory

12 Answers

0 votes
by (162k points)
Try setting the encoding via setControlEncoding()

FTPClient ftp = new FTPClient(host);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
{
ftp.get(files[i]);
}

com.enterprisedt.net.ftp.FTPException: Can't open fil?n?me.txt: No such file or directory
0 votes
by
      ftp = new FTPClient();

      //Set the control socket's encoding.
      //Can only do this if not connected
      //I am a chinese,so I use gb2312 encodeing
      log.info("setControlEncoding gb2312");
      ftp.setControlEncoding("gb2312");

      //set OS platform and Locale
      //It depend on you FTP server
      FTPFileParser parser = new UnixFileParser();
      FTPFileFactory fileFactory = new FTPFileFactory(parser);
      ftp.setFTPFileFactory(fileFactory);
      ftp.setParserLocale(Locale.US);
0 votes
by (460 points)
if I use FTPConnection Class?

(in .NET)
0 votes
by (51.6k points)
The .NET interfaces do not yet expose this as a property. However, you can do it by changing the source code for FTPControlSocket yourself. More specifically, change:
internal void InitStreams()
{
    Stream stream = controlSock.GetStream();
    writer = new StreamWriter(stream, Encoding.GetEncoding("US-ASCII"));
    reader = new StreamReader(stream, Encoding.GetEncoding("US-ASCII"));
}
to
internal void InitStreams()
{
    Stream stream = controlSock.GetStream();
    writer = new StreamWriter(stream, Encoding.GetEncoding("SOME-OTHER-ENCODING"));
    reader = new StreamReader(stream, Encoding.GetEncoding("SOME-OTHER-ENCODING"));
}

We will add a property to do this in the near future, but are in the middle of a fairly major refactoring exercise so we can't do it just at the moment.

- Hans (EDT)
0 votes
by (460 points)
I do this change:

internal void InitStreams()
{
   Stream stream = controlSock.GetStream();
   /*
   writer = new StreamWriter(stream, Encoding.GetEncoding("US-ASCII"));
   reader = new StreamReader(stream, Encoding.GetEncoding("US-ASCII"));
   */
   writer = new StreamWriter(stream, Encoding.GetEncoding("big5"));
   reader = new StreamReader(stream, Encoding.GetEncoding("big5"));
}


it still not work, and sand me this exception:

ERROR [FTPcliect.Form1] 8 六月 2006 10-57-37.628 : System.FormatException: Unexpected number of fields: 3
   at EnterpriseDT.Net.Ftp.WindowsFileParser.Parse(String raw)
   at EnterpriseDT.Net.Ftp.FTPFileFactory.Parse(String[] files)
   at EnterpriseDT.Net.Ftp.FTPClient.DirDetails(String dirname)
   at EnterpriseDT.Net.Ftp.FTPConnection.GetFileInfos()
   at FTPcliect.Form1.listServerDirectory() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 724
ERROR [FTPcliect.Form1] 8 六月 2006 10-57-37.643 : System.FormatException: Unexpected number of fields: 3
   at FTPcliect.Form1.listServerDirectory() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 737
   at FTPcliect.Form1.btnConnect_Click() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 778
0 votes
by (460 points)
I try to change log level from INFO to DEBUG

INFO [FTPcliect.Form1] 8 六月 2006 11-14-04.290 : 列出資料夾
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.290 : ---> SYST
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.321 : 215 Windows_NT
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.337 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.368 : 227 Entering Passive Mode (61,56,69,35,107,9)
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.384 : ---> LIST .
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.415 : 125 Data connection already open; Transfer starting.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-14-04.602 : 226 Transfer complete.
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-14-04.602 : Found 12 listing lines
DEBUG [EnterpriseDT.Net.Ftp.FTPFileFactory] 8 六月 2006 11-14-07.555 : Unexpected number of fields: 3
ERROR [FTPcliect.Form1] 8 六月 2006 11-14-07.649 : System.FormatException: Unexpected number of fields: 3
   at EnterpriseDT.Net.Ftp.WindowsFileParser.Parse(String raw)
   at EnterpriseDT.Net.Ftp.FTPFileFactory.Parse(String[] files)
   at EnterpriseDT.Net.Ftp.FTPClient.DirDetails(String dirname)
   at EnterpriseDT.Net.Ftp.FTPConnection.GetFileInfos()
   at FTPcliect.Form1.listServerDirectory() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 724
ERROR [FTPcliect.Form1] 8 六月 2006 11-14-07.665 : System.FormatException: Unexpected number of fields: 3
   at FTPcliect.Form1.listServerDirectory() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 737
   at FTPcliect.Form1.btnConnect_Click() in c:\documents and settings\benjaminchang\my documents\visual studio projects\advantech_ftp\ftpclient\form1.cs:line 778


in the remote folder, there are 12 items
folder * 11, file * 1
and the 11th folder is named in Chinese


I still try~~
0 votes
by (460 points)
I add some logs, to show folder name.

DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-42-23.746 : ---> LIST .
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-42-23.762 : 125 Data connection already open; Transfer starting.
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-06-06  07:38PM       <DIR>          965PreLaunch)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-30-06  03:23PM       <DIR>          eDM)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-06-06  07:33PM       <DIR>          eNetWorking)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-07-06  07:18PM       <DIR>          eng)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-02-06  12:12PM                   42 index.htm)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-01-06  09:56AM       <DIR>          Intel_ICRT)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-10-06  12:18PM       <DIR>          scripts-include)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-11-06  10:46AM       <DIR>          site_twn)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-12-06  11:18AM       <DIR>          sites)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-26-06  12:32PM       <DIR>          twn)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(05-19-06  07:56PM       <DIR>          UploadTest)
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-08-06  11:13AM       <DIR>          )
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 8 六月 2006 11-42-23.996 : 226 Transfer complete.
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.996 : Found 12 listing lines


and the question is: it can't show Chinese folder name:

DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 8 六月 2006 11-42-23.778 : lines.Add(06-08-06 11:13AM <DIR> )


I try "big5" and "950", both not work!

        internal void InitStreams()
        {
            Stream stream = controlSock.GetStream();
         /*
         writer = new StreamWriter(stream, Encoding.GetEncoding("US-ASCII"));
         reader = new StreamReader(stream, Encoding.GetEncoding("US-ASCII"));
         */
         /*
         writer = new StreamWriter(stream, Encoding.GetEncoding("big5"));
         reader = new StreamReader(stream, Encoding.GetEncoding("big5"));
         */
         writer = new StreamWriter(stream, Encoding.GetEncoding(950));
         reader = new StreamReader(stream, Encoding.GetEncoding(950));
      }
0 votes
by (162k points)
There's also a property in FTPClient and FTPConnection called ParsingCulture that you will need to set.
0 votes
by (460 points)
thanks for your opinion, I set this property:

ftpConnection1.ServerAddress = host;
ftpConnection1.ServerPort = Int32.Parse(port);
ftpConnection1.UserName = user;
ftpConnection1.Password = password;

ftpConnection1.ParsingCulture = new System.Globalization.CultureInfo("zh-TW");

ftpConnection1.Connect();


but the problem is the same, nothing change......

test, try, test, try, test, try......$%&@#
0 votes
by (162k points)
One last thing - I assume that the FTP server is showing the Chinese names correctly? What do you see in a command-line FTP client when you do 'dir' or 'ls'?

Categories

...