getting Connection refused exception when trying to upload a file to the server using FTP
public class FileUpload {
public static void main(String args[]){
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("192.168.10.185");
client.login("saranyas", "kspl1234");
int reply = client.getReplyCode();
if (!client.isConnected()) {
System.out.println("FTP server refused connection." + reply);
client.disconnect();
System.exit(1);
} else {
System.out.println("FTP server connected." + reply);
}
// Create an InputStream for the file to be uploaded
File f= new File("/home/Jyothisreea/Desktop/demo.doc");
fis = new FileInputStream(f);
// Store file to server
client.storeFile(f.getName(), fis);
client.logout();
} catch (IOException exp) {
System.out.println(exp.getMessage());
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException exp) {
System.out.println(exp.getMessage());
}
}
}
}
This is my program when i am trying to run it iam getting the following exception
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.开发者_JAVA技巧java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(FtpURLConnection.java:460)
at components.SimpleFTPClient.uploadFile(SimpleFTPClient.java:83)
at components.SimpleFTPClient.main(SimpleFTPClient.java:175
)
Why is this exception what should i do to overcome ....
Thanks
The normal cause of "connection refused" exceptions is that either:
- no FTP service is currently running on the machine / port you are trying to use, or
- a hardware or software firewall is blocking you from connecting.
If either of these is the case, then you won't be able to connect with a regular FTP client either.
精彩评论