001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.file.remote; 018 019 import java.io.IOException; 020 import javax.net.ssl.SSLException; 021 022 import org.apache.camel.component.file.GenericFileOperationFailedException; 023 import org.apache.camel.util.ObjectHelper; 024 import org.apache.commons.net.ftp.FTPClientConfig; 025 import org.apache.commons.net.ftp.FTPSClient; 026 027 /** 028 * FTP Secure (FTP over SSL/TLS) operations 029 * 030 * @version 031 */ 032 public class FtpsOperations extends FtpOperations { 033 034 public FtpsOperations(FTPSClient client, FTPClientConfig clientConfig) { 035 super(client, clientConfig); 036 } 037 038 @Override 039 public boolean connect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException { 040 boolean answer = super.connect(configuration); 041 042 FtpsConfiguration config = (FtpsConfiguration) configuration; 043 if (answer) { 044 try { 045 String execProt = config.getExecProt(); 046 Long execPbsz = config.getExecPbsz(); 047 // use default values for prop and pbsz, unless told to not do so 048 if (!config.isDisableSecureDataChannelDefaults()) { 049 if (ObjectHelper.isEmpty(execProt)) { 050 execProt = "P"; 051 } 052 if (ObjectHelper.isEmpty(execPbsz)) { 053 execPbsz = 0L; 054 } 055 } 056 057 if (execPbsz != null) { 058 log.debug("FTPClient initializing with execPbsz={}", execPbsz); 059 getFtpClient().execPBSZ(execPbsz); 060 } 061 if (execProt != null) { 062 log.debug("FTPClient initializing with execProt={}", execProt); 063 getFtpClient().execPROT(execProt); 064 } 065 } catch (SSLException e) { 066 throw new GenericFileOperationFailedException(client.getReplyCode(), 067 client.getReplyString(), e.getMessage(), e); 068 } catch (IOException e) { 069 throw new GenericFileOperationFailedException(client.getReplyCode(), 070 client.getReplyString(), e.getMessage(), e); 071 } 072 } 073 074 return answer; 075 } 076 077 @Override 078 protected FTPSClient getFtpClient() { 079 return (FTPSClient) super.getFtpClient(); 080 } 081 082 }