You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (JIRA)" <ji...@apache.org> on 2016/01/07 05:59:39 UTC

[jira] [Updated] (NET-585) Cannot store file by ftpclient in "ISO-8859-1" for chinese words "理.doc" or "理分册.doc"

     [ https://issues.apache.org/jira/browse/NET-585?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated NET-585:
---------------------
    Description: 
I use commons-net package to build a project " send files to a ftp server provide by windows"
and the code look like this:
{code}
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());
            }
        }
    }
{code}
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. 


  was:
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. 



> 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:
> {code}
> 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());
>             }
>         }
>     }
> {code}
> 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)