Hello there!
An unit test attached.
Jiří Kuhn.
package org.apache.ftpserver.clienttests;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
/**
* @author Jiri Kuhn
*/
public class CharsetTest extends ClientTestTemplate {
private static final String CHARSET = "cp1250";
private static final byte[] FILE_NAME_BYTES = {(byte) 0xec, (byte) 0x9a, (byte) 0xe8, (byte) 0xf8, (byte) 0x9e,
(byte) 0xfd, (byte) 0xe1, (byte) 0xed, (byte) 0xe9};
private static String FILE_NAME;
@Override
protected void setUp() throws Exception {
super.setUp();
FILE_NAME = new String(FILE_NAME_BYTES, CHARSET);
client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
}
protected FTPClient createFTPClient() throws Exception {
FTPClient client = new FTPClient();
client.setControlEncoding(CHARSET); // using "utf-8" is ok
return client;
}
/**
* Inspiration in [EMAIL PROTECTED] org.apache.ftpserver.clienttests.I18NTest#testStoreWithUTF8FileName()}.
*/
public void testStoreFile() throws Exception {
File testFile = new File(ROOT_DIR, FILE_NAME);
InputStream in = new ByteArrayInputStream(FILE_NAME_BYTES);
try {
assertTrue(client.storeFile(FILE_NAME, in));
} finally {
in.close();
}
assertTrue(testFile.exists());
}
/**
* Inspiration in [EMAIL PROTECTED] ListTest#testListFilesInDir()}.
*/
public void testList() throws Exception {
File testFile = new File(ROOT_DIR, FILE_NAME);
testFile.createNewFile();
FTPFile[] files = client.listFiles("/");
assertEquals(FILE_NAME, files[0].getName());
}
}