You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Rainer Englisch <ra...@osc-ims.de> on 2004/02/25 10:47:16 UTC

VFS: passive protocol

Hello,

I use virtual file system api in a project. My application needs to
write to a ftp server. The firewall was opened to support ftp but my
application can't open a data connection to the ftp-server. I suppose
that the active protocol that vfs uses is the problem. Is there a way to
change the protocol to passive?

It is quite urgent. Thanks for your help in advance.


Rainer


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


RE: passive protocol

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> -----Original Message-----
> From: Rainer Englisch [mailto:rainer.englisch@osc-ims.de] 
> Sent: den 25 februari 2004 10:47
> To: commons-dev@jakarta.apache.org
> Subject: VFS: passive protocol
> 
> 
> Hello,
> 
> I use virtual file system api in a project. My application 
> needs to write to a ftp server. The firewall was opened to 
> support ftp but my application can't open a data connection 
> to the ftp-server. I suppose that the active protocol that 
> vfs uses is the problem. Is there a way to change the 
> protocol to passive?
> 
> It is quite urgent. Thanks for your help in advance.

You're going to have to hack the VFS code directly, I'm afraid.
So start by grabbing the source from cvs.

The class is: org.apache.commons.vfs.provider.ftp.FtpFileSystem.

You'll find a method named createConnection:

    /**
     * Creates a new connection to the server.
     */
    private FTPClient createConnection()
        throws FileSystemException
    {
        try
        {
            final FTPClient client = new FTPClient();

            try
            {
                client.connect( hostname, port );

                int reply = client.getReplyCode();
                if ( !FTPReply.isPositiveCompletion( reply ) )
                {
                    throw new FileSystemException(
"vfs.provider.ftp/connect-rejected.error", hostname );
                }

                // Login
                if ( !client.login( username, password ) )
                {
                    throw new FileSystemException(
"vfs.provider.ftp/login.error", new Object[]{hostname, username}, null
);
                }

>>>>>>>>>>>>>   client.enterLocalPassiveMode(); <<<<<<<<<<<<<<<<< Add
this

                // Set binary mode
                if ( !client.setFileType( FTP.BINARY_FILE_TYPE ) )
                {
                    throw new FileSystemException(
"vfs.provider.ftp/set-binary.error", hostname );
                }
            }
            catch ( final IOException e )
            {
                closeConnection( client );
                throw e;
            }

            return client;
        }
        catch ( final Exception exc )
        {
            throw new FileSystemException(
"vfs.provider.ftp/connect.error", new Object[]{hostname}, exc );
        }
    }

add:

                client.enterLocalPassiveMode();

just after the login, as I have done in the example above.

Hope that helps.

/LS



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