commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guillermo Vasconcelos" <gvasconce...@baufest.com>
Subject RE: [VFS] Problems with FTP
Date Fri, 31 Mar 2006 17:46:20 GMT
If you have access to the windows FTP server, you can set the directory
listing to be in Unix style.
That worked for me.
Hope that helps.

Guillermo

-----Original Message-----
From: Joseph, Ronald [mailto:Ronald.Joseph@Dresdner-Bank.com] 
Sent: Viernes, 31 de Marzo de 2006 10:02
To: 'commons-user@jakarta.apache.org'
Subject: [VFS] Problems with FTP

Hello,

I have a (big) Problem with the FTP-VFS. I try to transfer a file from a
FTP-Server to the local maschine. When I use a UNIX (Sun) FTP-Server,
then
all works fine.
When I use a Win-FTP-server (I think is it a W2K-maschine), then I can't
tranfer the file.

I have writte the following test-program :
----- snipp ------------
package test;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.vfs.FileChangeEvent;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileListener;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemConfigBuilder;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.RandomAccessContent;
import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.impl.DefaultFileMonitor;
import org.apache.commons.vfs.provider.ftp.FtpFileSystemConfigBuilder;
import org.apache.commons.vfs.util.RandomAccessMode;
import org.apache.commons.net.ftp.parser.UnixFTPEntryParser;

public class VFSTest2 {
  
  public static void main (String main []) {
    new VFSTest2 ().run ();
  }
  
  protected void run () {
    try {
      FileSystemOptions fso = new FileSystemOptions ();
      FtpFileSystemConfigBuilder ffscb =
FtpFileSystemConfigBuilder.getInstance ();
      System.out.println ("ffscb.getEntryParser ():=" +
ffscb.getEntryParser
(fso));
      ffscb.setEntryParser (fso,
"org.apache.commons.net.ftp.parser.UnixFTPEntryParser");
      System.out.println ("ffscb.getEntryParser ():=" +
ffscb.getEntryParser
(fso));
      
      FileSystemManager mgr = VFS.getManager ();
      FileSystemConfigBuilder fscb = mgr.getFileSystemConfigBuilder
("ftp");
      
      // String ftpURI = "ftp://UNIXHOST/PATH/TO/DIR";
      String ftpURI = "ftp://WIN_HOST/PATH/TO/DIR";
      
      FileObject fObj = mgr.resolveFile (ftpURI, fso);
      FileObject children [] = fObj.getChildren ();
      for (int x = 0; x < children.length; x++) {
        System.out.println (x + "::" + children [x]);
      }
        
      FileObject src = mgr.resolveFile (ftpURI + "/" + children
[0].getName
().getBaseName (), fso);
      SimpleDateFormat sdf = new SimpleDateFormat ("dd.MMM yyyy
HH:mm:ss");
      FileContent srcContent = src.getContent ();
      System.out.println ("srcContent.getAttributes ():=" +
srcContent.getAttributes ());
      System.out.println ("srcContent.getSize ():=" + srcContent.getSize
());
      System.out.println ("srcContent.getLastModifiedTime ():=" +
sdf.format
(new Date (srcContent.getLastModifiedTime ())));
      System.out.println ("srcContent.getContentInfo
().getContentEncoding
():=" + 
        srcContent.getContentInfo ().getContentEncoding ());
      System.out.println ("srcContent.getContentInfo ().getContentType
():="
+ 
        srcContent.getContentInfo ().getContentType ());
    } catch (Exception ex) {
      ex.printStackTrace ();
    }
  }
}
---- snapp ---------

Now I run this in a DOS-Box from:
C:\projekte\Connector2\development>java test.VFSTest2
ffscb.getEntryParser ():=null
ffscb.getEntryParser
():=org.apache.commons.net.ftp.parser.UnixFTPEntryParser
0::ftp://UNIXHOST/PATH/TO/DIR/--help
1::ftp://UNIXHOST/PATH/TO/DIR/--help.pub
srcContent.getAttributes ():={}
srcContent.getSize ():=895
srcContent.getLastModifiedTime ():=19.Aug 2004 00:00:00
srcContent.getContentInfo ().getContentEncoding ():=null
srcContent.getContentInfo ().getContentType ():=null

This is all correct.

When I try the Win-FTP-Server, I get the following output on the
console:
C:\projekte\Connector2\development>java test.VFSTest2
ffscb.getEntryParser ():=null
ffscb.getEntryParser
():=org.apache.commons.net.ftp.parser.UnixFTPEntryParser
org.apache.commons.vfs.FileSystemException: Could not list the contents
of
"ftp://WIN-HOST/PATH/TODIR" because it is not a folder.
        at
org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractF
ileO
bject.java:519)
        at test.VFSTest2.run(VFSTest2.java:44)
        at test.VFSTest2.main(VFSTest2.java:26)

Can enyone help me?

Best regards from Germany
Ronald

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message