Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8k views
in Java FTP by (520 points)
Hi guys,

chinese or japnese characters file names are listed with question mark. This happens only in windows. I'm using "utf-8" encoding.

sample:
FtpClient fc =new FtpClient();
fc.setCharacterEncoding("utf-8");
String[] arr=fc.dir();
for(int i=0;i<arr.length;i++)
{

System.out.println(arr[i]);
}

This code works good for linux. I tried with GBK and GB232 encoding too. Kindly help :(
using free version

9 Answers

0 votes
by (162k points)
Have you tried Big5?
0 votes
by (520 points)
Yes, I tried with Big5 too. Still question mark symbol appears. This happens for windows machines :(
0 votes
by (162k points)
You're using setControlEncoding("Big5")?
0 votes
by (520 points)
yes exactly.
0 votes
by (520 points)
any ideas guys? any experiment u want me to do? i shall do
0 votes
by (162k points)
post the code you are using.
0 votes
by (520 points)
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPMessageListener;
import com.enterprisedt.net.ftp.*;
import com.enterprisedt.net.ftp.FTPFile;
import java.util.logging.*;
import java.util.*;
class FTPmine
{ private static final Logger LOGGER = Logger.getLogger(FTPmine.class.getName());
//Logger
private static Logger log = Logger.getLogger(FTPmine.class.getName());
public static void main(String args[])
{
try
{
FTPmine fu=new FTPmine();
FTPClient fc=null;
if(args[0].equals("1"))
{
fc=fu.getFTPClient("felog-w2k8","viswesh","viswesh");
}
String[] arr=fc.dir();
System.out.println("-->"+fc.getControlEncoding()+fc.pwd());

for(int i=0;i<arr.length;i++)
{

System.out.println(arr[i]);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

public static FTPClient getFTPClient(String hostName, String userName, String password)
throws Exception {
log.info("Connecting");
try {
FTPClient ftp = new FTPClient();
if(!ftp.connected())
{
ftp.setControlEncoding("utf-8");
System.out.println("encoding set da");
ftp.setRemoteHost(hostName);
ftp.connect();
}
else
{
System.out.println("encoding notset");
}
LOGGER.log(Level.FINER," FTP client {0}",ftp);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
loginFTPClient(userName, password,ftp);
// set up passive ASCII transfers
log.info("Setting up Active, BINARY transfers");
ftp.setConnectMode(FTPConnectMode.ACTIVE);
ftp.setType(FTPTransferType.BINARY);
return ftp;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
private static void loginFTPClient(String user, String password,FTPClient ftp)
throws Exception {
// login
log.info("Logging in");
ftp.login(user, password);
}

}
0 votes
by (520 points)
anythin wrong in the code?? should i have to try some other method?
0 votes
by (520 points)
Hi guys, I found the answer

Check the below things if u get the same problem.

1) Ftp server should support utf-8 encoding

2) The OS where the FTP server installed should support that language

In my case, all linux machines by default supports utf-8. Windows IIS 7.0 alone supports utf-8. IIS 7 is the latest and available only in vista and windows7

Thanks for your support :)

My advice: always use utf-8. If utf-8 does not work check for the above things

Categories

...