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

Dale Lee commented on NET-573:
------------------------------

Here is snippet of the code:
{code} 
        FTPClient ftpClient = new FTPClient();
        FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_AS400);
        conf.setDefaultDateFormatStr("MM/dd/yy HH:mm:ss");
        
        ftpClient.configure(conf);
        System.out.println(conf.getDefaultDateFormatStr());
        
        try {
            ftpClient.connect(server, port);
            ftpClient.login(user, pass);
 
            // use local passive mode to pass firewall
            ftpClient.enterLocalPassiveMode();
 
            // get details of a file or directory
            String remoteFilePath = "/DRV/AUDWRKSHET";
            System.out.println("Num of files: " + 
ftpClient.listFiles(remoteFilePath).length);
            FTPFile ftpFile = ftpClient.listFiles(remoteFilePath)[0];
            if (ftpFile != null) {
                String name = ftpFile.getName();
                long size = ftpFile.getSize();
               // String timestamp = 
ftpFile.getTimestamp().getTime().toString();
                String type = ftpFile.isDirectory() ? "Directory" : "File";
                                System.out.println(ftpFile.getRawListing());
                                System.out.println(ftpFile.toString());
                System.out.println("Name: " + name);
                System.out.println("Size: " + size);
                System.out.println("Type: " + type);
                //System.out.println("Timestamp: " + timestamp);
                System.out.println("Time: " + ftpFile.getTimestamp());
            } else {
                System.out.println("The specified file/directory may not 
exist!");
            }
 
            ftpClient.logout();
            ftpClient.disconnect();
 
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    ftpClient.disconnect();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
{code}

Here is output:
MM/dd/yy HH:mm:ss
Num of files: 1
ZFTPDEV          9069 05/20/15 15:36:52 *STMF      
/DRV/AUDWRKSHET/AUDWRK0204232015114625.PDF
ZFTPDEV          9069 05/20/15 15:36:52 *STMF      
/DRV/AUDWRKSHET/AUDWRK0204232015114625.PDF
Name: AUDWRK0204232015114625.PDF
Size: 9069
Type: File
Time: null


> CLONE - Retrieving files from AS400 FTP systems returns null timestamps in 
> FTPFile.getTimestamp
> -----------------------------------------------------------------------------------------------
>
>                 Key: NET-573
>                 URL: https://issues.apache.org/jira/browse/NET-573
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 2.2, 3.2, 3.3
>         Environment: Commons Net 3.2
> FTP System: AS400 systems
> I5/OS Version 5 Release 4 Modification 0
>            Reporter: Dale Lee
>            Priority: Minor
>
> We are trying to list files from AS400 systems and retrieve the timestamps 
> from these files using the following code:
> {code}
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.io.PrintWriter;
> import java.net.InetAddress;
> import java.net.UnknownHostException;
> import org.apache.commons.net.PrintCommandListener;
> import org.apache.commons.net.ftp.FTP;
> import org.apache.commons.net.ftp.FTPClient;
> import org.apache.commons.net.ftp.FTPHTTPClient;
> import org.apache.commons.net.ftp.FTPClientConfig;
> import org.apache.commons.net.ftp.FTPConnectionClosedException;
> import org.apache.commons.net.ftp.FTPFile;
> import org.apache.commons.net.ftp.FTPReply;
> import org.apache.commons.net.ftp.FTPSClient;
> import org.apache.commons.net.io.CopyStreamEvent;
> import org.apache.commons.net.io.CopyStreamListener;
> import org.apache.commons.net.util.TrustManagerUtils;
> public final class FTPAccess {
>       private String server;
>       private String username;
>       private String password;
>       private String path ;
>       public String getPath() {
>               return path;
>       }
>       public void setPath(String path) {
>               this.path = path;
>       }
>       public static void main(String[] args) throws UnknownHostException {
>               FTPAccess ftpAccess = new FTPAccess();
>               ftpAccess.setServer("X.X.X.X");
>               ftpAccess.setUsername("XXXXXX");
>               ftpAccess.setPassword(XXXXXXX");
>               ftpAccess.setPath("/reports");
>               ftpAccess.getFile();
>       }
>       public void getFile() throws UnknownHostException {
>               
>               FTPClient ftpClient = new FTPClient();
>               
>               try {
>                       InetAddress serveIPAddress = 
> InetAddress.getByName(server);
>                       ftpClient.setPassiveLocalIPAddress(serveIPAddress);
>                       ftpClient.connect(serveIPAddress);
>                       System.out.println("Connected to " + server + ".");
>                       int reply = ftpClient.getReplyCode();
>                       if (!FTPReply.isPositiveCompletion(reply)) {
>                               System.err.println("FTP server refused 
> connection.");
>                               System.err.println(ftpClient.getReplyString());
>                               ftpClient.disconnect();
>                       } else {
>                       }
>                       if (!ftpClient.login(username, password)) {
>                               System.out.println(ftpClient.getReplyString());
>                               ftpClient.logout();
>                       } else{
>                               diplayContent(ftpClient, path);
>                       }
>               } catch (IOException e) {
>                       if (ftpClient.isConnected()) {
>                               try {
>                                       ftpClient.disconnect();
>                               } catch (IOException ioException) {
>                                       // do nothing
>                               }
>                       }
>                       System.err.println("Could not connect to server.");
>                       // e.printStackTrace();
>                       System.exit(1);
>               }
>               // } catch (FTPConnectionClosedException e) {
>               // error = true;
>               // System.err.println("Server closed connection.");
>               // e.printStackTrace();
>               // } catch (IOException e) {
>               // error = true;
>               // e.printStackTrace();
>               // } finally {
>               // if (ftp.isConnected()) {
>               // try {
>               // ftp.disconnect();
>               // } catch (IOException f) {
>               // // do nothing
>               // }
>               // }
>               // }
>       } // end main
>       public String getServer() {
>               return server;
>       }
>       public void setServer(String server) {
>               this.server = server;
>       }
>       public String getUsername() {
>               return username;
>       }
>       public void setUsername(String username) {
>               this.username = username;
>       }
>       public String getPassword() {
>               return password;
>       }
>       public void setPassword(String password) {
>               this.password = password;
>       }
>       
>       public void diplayContent(FTPClient ftpClient, String path) throws 
> IOException {
>               System.out.println(path);
>               for (FTPFile ftpFile : ftpClient.listFiles(path)) {
>                       if(ftpFile.isDirectory() ){
>                               diplayContent(ftpClient, 
> path+"/"+ftpFile.getName());
>                       } else{
>                               System.out.println(path+"/"+ftpFile.getName());
>                               System.out.println(ftpFile.getTimestamp());
>                       }
>               }
>               
>       }
> }
> {code}
> The LIST command which is used internally in the FTPClient retrieves the 
> timestamps successfully. However after parsing the FTPFile has a null value 
> for the timestamp field.
> The null value is returned just when a user place the file in the AS400 usint 
> the NetServer Servivice. This is used to share foldes between windows network 
> and the AS/400
> Please help us fix this problem. It is not critical to us.



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

Reply via email to