Skip to content

Commit 326eab2

Browse files
committed
Fix race condition in FTP close
1 parent 2bf2010 commit 326eab2

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

ftp/src/main/java/ch/cyberduck/core/ftp/FTPClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class FTPClient extends FTPSClient {
5959
private final SSLSocketFactory sslSocketFactory;
6060

6161
private Protocol protocol;
62+
public Socket dataSocket;
6263

6364
/**
6465
* Map of FEAT responses. If null, has not been initialised.
@@ -89,6 +90,7 @@ protected Socket _openDataConnection_(final String command, final String arg) th
8990

9091
@Override
9192
protected void _prepareDataSocket_(final Socket socket) {
93+
this.dataSocket = socket;
9294
if(preferences.getBoolean("ftp.tls.session.requirereuse")) {
9395
if(socket instanceof SSLSocket) {
9496
// Control socket is SSL

ftp/src/main/java/ch/cyberduck/core/ftp/FTPReadFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void close() throws IOException {
101101
return;
102102
}
103103
try {
104-
super.close();
104+
session.getClient().dataSocket.shutdownOutput();
105105
if(session.isConnected()) {
106106
// Read 226 status after closing stream
107107
int reply = session.getClient().getReply();
@@ -122,6 +122,7 @@ else if(!status.isComplete()) {
122122
}
123123
}
124124
finally {
125+
super.close();
125126
close.set(true);
126127
}
127128
}

ftp/src/main/java/ch/cyberduck/core/ftp/FTPWriteFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void close() throws IOException {
9292
return;
9393
}
9494
try {
95-
super.close();
95+
session.getClient().dataSocket.shutdownOutput();
9696
if(session.isConnected()) {
9797
// Read 226 status after closing stream
9898
if(!FTPReply.isPositiveCompletion(session.getClient().getReply())) {
@@ -112,6 +112,7 @@ else if(!status.isComplete()) {
112112
}
113113
}
114114
finally {
115+
super.close();
115116
close.set(true);
116117
}
117118
}

0 commit comments

Comments
 (0)