Skip to main content

Socket Exception only in Java 7

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
6 replies [Last post]
bobjob
Offline
Joined: 2005-09-30

I got a Socket Exception in Java 7 that isnt present in previous versions of Java.
Is this a bug or a new a new security update.

I can no longer upload FTP files via java because of this exception.

java.net.SocketException: Permission denied: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at ftp.FTPConnector.readLine(FTPConnector.java:202)
------------------------------------------------------------------------------------------------------

Is there a workaround for this issue? or is it a bug?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
prunge
Offline
Joined: 2004-05-06
hansje
Offline
Joined: 2011-09-21

Same problem for me.

ksfreitas
Offline
Joined: 2011-08-18

I have same problem. Using Windows 7 x64 with Java7 x64.

Fung
Offline
Joined: 2011-04-04

ksfreitas wrote:

I have same problem. Using Windows 7 x64 with Java7 x64.

Me to, but is Windows 7 32bit and JRE7, and after turned off the windows firewall is working fine.

bobjob
Offline
Joined: 2005-09-30

TEST CASE:

import java.io.*;
import java.net.*;

public class Test {
public static void main(String args[]) throws Exception {

String username = "<ENTER YOUR USERNAME>";
String password = "<ENTER YOUR PASSWORD>";
String host = "<ENTER DOMAIN NAME OF HOST>";

java.net.Socket socket = new Socket(host, 21);
java.io.BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
java.io.BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

String response = reader.readLine();
System.out.println("Response: " + response);
if ( response.startsWith("220-")) {
System.out.println("Complex response");
while (response.startsWith("220-")) {
response = reader.readLine();
System.out.println("Response: " + response);
}
}
writer.write("USER " + username + "\r\n");
writer.flush();

response = reader.readLine();
System.out.println("Response: " + response);

if ( response.startsWith("331-")) {
System.out.println("Complex response");
while (response.startsWith("331-")) {
response = reader.readLine();
System.out.println("Response: " + response);
}
}
if (!response.startsWith("331 ")) {
throw new IOException("SimpleFTP received an unknown response after sending the user: " + response);
}

writer.write("PASS " + password + "\r\n");
writer.flush();

response = reader.readLine();
System.out.println("Response: " + response);
if ( response.startsWith("230-")) {
System.out.println("Complex response");
while (response.startsWith("230-")) {
response = reader.readLine();
System.out.println("Response: " + response);
}
}

writer.write("PASV" + "\r\n");
writer.flush();

System.out.println("Start of Java 7 exception");
System.out.println(reader.readLine());
System.out.println("IF YOU SEE THIS, THEN THERE IS NO EXCEPTION");

reader.close();
writer.close();
}
}

bobjob
Offline
Joined: 2005-09-30

Windows 7 32bit

java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)