INT-2048
This commit is contained in:
committed by
Mark Fisher
parent
a1cbb51da8
commit
b1f4123e12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,7 +51,7 @@ class FtpSession implements Session {
|
||||
public boolean remove(String path) throws IOException {
|
||||
Assert.hasText(path, "path must not be null");
|
||||
boolean completed = this.client.deleteFile(path);
|
||||
if (!completed){
|
||||
if (!completed) {
|
||||
throw new IOException("Failed to delete '" + path + "'. Server replied with: " + client.getReplyString());
|
||||
}
|
||||
return completed;
|
||||
@@ -63,25 +63,28 @@ class FtpSession implements Session {
|
||||
return this.client.listFiles(path);
|
||||
}
|
||||
|
||||
public void read(String path, OutputStream fos) throws IOException{
|
||||
public void read(String path, OutputStream fos) throws IOException {
|
||||
Assert.hasText(path, "path must not be null");
|
||||
Assert.notNull(fos, "outputStream must not be null");
|
||||
boolean completed = this.client.retrieveFile(path, fos);
|
||||
if (!completed){
|
||||
throw new IOException("Failed to copy '" + path + "'. Server replied with: " + client.getReplyString());
|
||||
if (!completed) {
|
||||
throw new IOException("Failed to copy '" + path +
|
||||
"'. Server replied with: " + this.client.getReplyString());
|
||||
}
|
||||
logger.info("File have been successfully transfered to: " + path);
|
||||
}
|
||||
|
||||
public void write(InputStream inputStream, String path) throws IOException{
|
||||
public void write(InputStream inputStream, String path) throws IOException {
|
||||
Assert.notNull(inputStream, "inputStream must not be null");
|
||||
Assert.hasText(path, "path must not be null");
|
||||
boolean completed = client.storeFile(path, inputStream);
|
||||
if (!completed){
|
||||
boolean completed = this.client.storeFile(path, inputStream);
|
||||
if (!completed) {
|
||||
throw new IOException("Failed to write to '" + path
|
||||
+ "'. Server replied with: " + client.getReplyString());
|
||||
+ "'. Server replied with: " + this.client.getReplyString());
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("File has been successfully transfered to: " + path);
|
||||
}
|
||||
logger.info("File have been successfully transfered to: " + path);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -97,21 +100,24 @@ class FtpSession implements Session {
|
||||
|
||||
public boolean isOpen() {
|
||||
try {
|
||||
client.noop();
|
||||
} catch (Exception e) {
|
||||
this.client.noop();
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void rename(String pathFrom, String pathTo) throws IOException{
|
||||
client.deleteFile(pathTo);
|
||||
boolean completed = client.rename(pathFrom, pathTo);
|
||||
if (!completed){
|
||||
this.client.deleteFile(pathTo);
|
||||
boolean completed = this.client.rename(pathFrom, pathTo);
|
||||
if (!completed) {
|
||||
throw new IOException("Failed to rename '" + pathFrom +
|
||||
"' to " + pathTo + "'. Server replied with: " + client.getReplyString());
|
||||
"' to " + pathTo + "'. Server replied with: " + this.client.getReplyString());
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("File has been successfully renamed from: " + pathFrom + " to " + pathTo);
|
||||
}
|
||||
logger.info("File have been successfully renamed from: " + pathFrom + " to " + pathTo);
|
||||
}
|
||||
|
||||
public void mkdir(String directory) throws IOException {
|
||||
@@ -124,4 +130,5 @@ class FtpSession implements Session {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,13 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-create-directory" type="xsd:string" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify whether to automatically create the remote target directory if it doesn't exist.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="remote-file-separator" type="xsd:string" default="/">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
|
||||
|
||||
<bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
|
||||
<property name="host" value="192.168.1.155"/>
|
||||
<property name="username" value="oleg"/>
|
||||
<property name="host" value="192.168.28.143"/>
|
||||
<property name="username" value="user"/>
|
||||
<property name="password" value="password"/>
|
||||
<property name="bufferSize" value="1000000"/>
|
||||
</bean>
|
||||
@@ -17,7 +17,8 @@
|
||||
<int:channel id="ftpChannel"/>
|
||||
|
||||
<int-ftp:outbound-channel-adapter
|
||||
auto-create-directory="true"
|
||||
session-factory="ftpSessionFactory"
|
||||
remote-directory="/home/ozhurakousky"
|
||||
remote-directory="./dsf/sdfsfs/sdffs"
|
||||
channel="ftpChannel"/>
|
||||
</beans>
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.integration.ftp.session;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
@@ -47,7 +47,6 @@ public class SessionFactoryTests {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user