HuangJie created NET-585:
----------------------------

             Summary: Cannot store file by ftpclient in "ISO-8859-1" for 
chinese words "理.doc" or "理分册.doc"
                 Key: NET-585
                 URL: https://issues.apache.org/jira/browse/NET-585
             Project: Commons Net
          Issue Type: Bug
          Components: FTP
    Affects Versions: 3.4
         Environment: 1.WebSphere Application Server    7.0.0.19
2.Redhat Linux 5.8
3.jdk 1.6 64bit
            Reporter: HuangJie


I use commons-net package to build a project " send files to a ftp server 
provide by windows"
and the code look like this:
public static void UploadFile(String localBaseDir, String remoteBaseDir,
                                  String fileName) throws Exception
    {
        
System.out.println("--------------------------------------------------");
        InputStream localIn = null;
        FTPClient ftp = ConnectFtpServer();
        try
        {
                System.out.println("localBaseDir:" + localBaseDir);
                System.out.println("remoteBaseDir:" + remoteBaseDir);
                System.out.println("fileName:" + fileName);
                System.out.println("encoding:" + 
System.getProperties().get("file.encoding"));
                System.out.println("new String:" + new 
String(fileName.getBytes((String)System.getProperties().get("file.encoding")),"ISO-8859-1"));
            File localFile = new File(localBaseDir
                                      );
            System.out.println("isexist="+localFile.exists());
            localIn = new BufferedInputStream(new FileInputStream(localFile));

            String romoteFileName = remoteBaseDir + fileName;
            // ftp.makeDirectory(new
            // String(remoteBaseDir.getBytes("GBK"),"ISO-8859-1"));
            
//System.out.println("makeDirectory:"+ftp.makeDirectory(remoteBaseDir) );
            ftpCreateDirectoryTree(ftp,remoteBaseDir);
            
System.out.println("changeWorkingDirectory:"+ftp.changeWorkingDirectory(remoteBaseDir));
            ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            
ftp.setControlEncoding((String)System.getProperties().get("file.encoding"));
            // boolean result = ftp.storeFile(romoteFileName, localIn);
            boolean result = ftp.storeFile(
                        remoteBaseDir+new 
String(fileName.getBytes((String)System.getProperties().get("file.encoding")),"ISO-8859-1"),
                                 localIn);
            System.out.println("result="+result);
            if (!result)
            {
                logger.log("文件上传备份失败");
                throw new Exception("文件上传备份失败!");
            }
            
            
System.out.println("--------------------------------------------------");
        }
        catch (Exception ex)
        {
            logger.log("UploadFile异常" + ex.getMessage());
        }
        finally
        {
            try
            {
                if (localIn != null)
                {
                    localIn.close();
                    DisconnectFtpServer(ftp);
                }
            }
            catch (IOException ex2)
            {
                logger.log("UploadFile close 异常" + ex2.getMessage());
            }
        }
    }
and I try to fix this problems by use different encoding ,but I failed.
by setting enterLocalPassiveMode
setControlEncoding
different string encoding .

I tried all above this and failed. 




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to