Howto delete file from FTP-Endpoint direct

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Howto delete file from FTP-Endpoint direct

eddi
Hi,

How I can send direct a file operation to the File-/FTP-Endpoint?
How I can delete Files over FileEndpointProducer?

I can create/change Files easy.

I not find a Way to delete only a created Files.

Inside my Example is the last Route, but can not delete the "fromJetty.txt" File.

package de.testandtry;

import java.util.Collection;
import java.util.Map;

import javax.activation.DataHandler;

import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;

public class Program extends RouteBuilder {
    
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.enableHangupSupport();
        main.addRouteBuilder(new Program());
        main.run(args);
    }
    
    /**
     * Let's configure the Camel routing rules using Java code...
     */
    public void configure() {
        
        // 1. Call
        from("jetty:http://localhost:7777/action/view")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setBody("<form method=\"post\" enctype=\"multipart/form-data\" action=\"./create\"><input name=\"fromJetty\" type=\"file\"><input type=\"submit\"></form>");
                }
            })
            ;
            
        // 2. Call
        from("jetty:http://localhost:7777/action/create")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    Map<String, DataHandler>  atts = exchange.getIn().getAttachments();
                    Collection<DataHandler> values = atts.values();
                    for (DataHandler dataHandler : values) {
                        Message message = exchange.getOut();
                        message.setBody(dataHandler.getInputStream());
                        message.setHeader(Exchange.FILE_NAME,dataHandler.getName());
                        break;
                    }
                }
            })
            .convertBodyTo(String.class)
            .to("ftp://user@localhost/share?password=123&fileName=fromJetty.txt")
            ;

        // 3. Call        
        from("jetty:http://localhost:7777/action/delete")
            .setBody(constant(""))
            .to("ftp://user@localhost/share?password=123&fileName=fromJetty.txt&delete=true")
            .to("mock:away");

    }
}


Best Regards
Eddi
Reply | Threaded
Open this post in threaded view
|

Re: Howto delete file from FTP-Endpoint direct

eddi
I find a Way for send direct File Opperations to the FTP Endpoint.

from("jetty:http://localhost:7777/action/delete")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    RemoteFileEndpoint<?> ftpEp = (RemoteFileEndpoint<?>) getContext().getEndpoint("ftp://user@localhost/share?password=123");
                    RemoteFileOperations<?> operation = ftpEp.createRemoteFileOperations();
                    operation.connect(ftpEp.getConfiguration());
                    boolean deleted = operation.deleteFile(ftpEp.getConfiguration().getDirectory()+"/"+"fromJetty.txt");
                    exchange.getOut().setBody("DELETED = "+deleted);
                    operation.disconnect();
                }
            });

Debug and Trace really helps very much.
Reply | Threaded
Open this post in threaded view
|

Re: Howto delete file from FTP-Endpoint direct

contactreji
If you are trying to delete a file after consuming from a ftp server using
ftp camel component, then put the option "delete=true" while configuring
the ftp consumer end point.

Make sure the ftp credentials u are using has rights to perform delete
operations .

Cheers
Reji
On 01/04/2014 3:01 pm, "eddi" <[hidden email]> wrote:

> I find a Way for send direct File Opperations to the FTP Endpoint.
>
> from("jetty:http://localhost:7777/action/delete")
>             .process(new Processor() {
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>                     RemoteFileEndpoint<?> ftpEp = (RemoteFileEndpoint<?>)
> getContext().getEndpoint("ftp://user@localhost/share?password=123");
>                     RemoteFileOperations<?> operation =
> ftpEp.createRemoteFileOperations();
>                     operation.connect(ftpEp.getConfiguration());
>                     boolean deleted =
>
> operation.deleteFile(ftpEp.getConfiguration().getDirectory()+"/"+"fromJetty.txt");
>                     exchange.getOut().setBody("DELETED = "+deleted);
>                     operation.disconnect();
>                 }
>             });
>
> Debug and Trace really helps very much.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Howto-delete-file-from-FTP-Endpoint-direct-tp5749570p5749617.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reji Mathews Sr. Engineer - Middleware Integrations / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB ) LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a Twitter - reji_mathews