commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject RE: passive protocol
Date Wed, 25 Feb 2004 13:16:46 GMT


> -----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


Mime
View raw message