This commit is contained in:
Oleg Zhurakousky
2011-10-18 12:17:14 -04:00
committed by Mark Fisher
parent a1cbb51da8
commit b1f4123e12
10 changed files with 139 additions and 106 deletions

View File

@@ -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 {
}
}
}
}

View File

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