[ 
https://issues.apache.org/jira/browse/NET-61?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12840558#action_12840558
 ] 

Philip Yao commented on NET-61:
-------------------------------

i have sloved.
My code is not work like this:
--------------------------------------------------------------
public boolean createDirectory(String pathName){ 
                 boolean success = true;
                 try{
                         if(!ftp.isConnected()) {
                                 this.connectFtpServer();
                         }
                         pathName = new String(pathName.getBytes("GBK"), 
"iso-8859-1");          
                         
                         FTPFile[] ftpFileArr = ftp.listFiles();
                         for(FTPFile f : ftpFileArr){
                                 if(pathName.equals(f.getName())){
                                         return true;
                                 }
                         }
                         
                         ftp.makeDirectory(pathName);  
                 }catch (Exception ie){ 
                         logger.error("创建目录出错!", ie); 
                         success = false;
                 }
                 return success;
         }
----------------------------------------------------
On the works fine (my notebook).I found the ftp log is :

220 Serv-U FTP Server v6.4 for WinSock ready...
USER user
331 User name okay, need password.
PASS user
230 User logged in, proceed.
CWD ????????
250 Directory changed to /????????
PASV
227 Entering Passive Mode (192,168,137,7,173,212)
227
SYST
215 UNIX Type: L8
PORT 192,168,137,7,4,152
200 PORT Command successful.
LIST
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.

-----------------------------------------------------
On the not work server(DELL 1950) .i found the log is no PASV.


So I change the Code like this:
public boolean createDirectory(String pathName){ 
                 boolean success = true;
                 try{
                         if(!ftp.isConnected()) {
                                 this.connectFtpServer();
                         }
                         pathName = new String(pathName.getBytes("GBK"), 
"iso-8859-1");
                         ftp.enterLocalPassiveMode();
                         FTPFile[] ftpFileArr = ftp.listFiles();
                         for(FTPFile f : ftpFileArr){
                                 if(pathName.equals(f.getName())){
                                         return true;
                                 }
                         }
                         
                         ftp.makeDirectory(pathName);  
                 }catch (Exception ie){ 
                         logger.error("创建目录出错!", ie); 
                         success = false;
                 }
                 return success;
         }
-------------------------------------------------------
Before call ftp.listFiles() , call ftp.enterLocalPassiveMode(); Frist;




> [net] FTPClient.listFiles() hangs on Red Hat Linux
> --------------------------------------------------
>
>                 Key: NET-61
>                 URL: https://issues.apache.org/jira/browse/NET-61
>             Project: Commons Net
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: Operating System: Linux
> Platform: PC
>            Reporter: George Van Treeck
>            Priority: Blocker
>
> A Java app that uses FTPClient to download a file from a website to Windows 
> XP 
> works properly. But, when the same app runs on Linux to download the same 
> file 
> from the same website, it hangs at listFiles().
> Using Java 1.5.0_03 on both the Windows XP and Linux. The version of Linux 
> used is Fedor Red Hat Linux Core 3 with all the latest updates. The following 
> segment of code from the program demonstrates the problem:
>               FTPClient ftp = new FTPClient();
>               ftp.connect(host);
>               reply = ftp.getReplyCode();
>               if (!FTPReply.isPositiveCompletion(reply)) {
>                 final String ftpStatus = ftp.getReplyString();
>                 ftp.disconnect();
>                 throw new IOException(
>                     "FTP server refused connection. Status: " +
>                    ftpStatus);
>               }
>               ftp.login(user, password);
>               reply = ftp.getReplyCode();
>               if (!FTPReply.isPositiveCompletion(reply)) {
>                 final String ftpStatus = ftp.getReplyString();
>                 ftp.disconnect();
>                 throw new IOException(
>                     "FTP server refused username/password. Status: " +
>                    ftpStatus);
>               }
>               String[] list = ftp.listNames();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to