You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Joseph, Ronald" <Ro...@Dresdner-Bank.com> on 2006/03/31 15:02:28 UTC

[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(AbstractFileO
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


Re: [VFS] Problems with FTP

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!

In case switching to unix-style isnt possible or didnt work, please try
running the libcheck tool for ftp.
This tool should be included in your VFS distribution.

java org.apache.commons.vfs.libcheck.FtpCheck username password host
directory

Where "directory" should be without trailing slash. And post the output.


> Best regards from Germany
>   
Greetings from Austria :-)

Ciao,
Mario


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