import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
public class FTPClient {
protected Socket sk;
protected BufferedReader in;
protected BufferedWriter out;
public static void main (String [] args){
FTPClient fc1 = new FTPClient("sitename.org",21);
fc1.Login("user", "password!");
}
FTPClient(String server, int port){
try{
this.sk = new Socket(server,port);
this.in = new BufferedReader(new InputStreamReader(sk.getInputStream()));
this.out = new BufferedWriter(new OutputStreamWriter(sk.getOutputStream()));
String response = in.readLine();
System.out.println(response);
}
catch(Exception e){
System.out.println(e);
}
}
public boolean Login(String user, String pass){
boolean success = false;
try{
sendOut("USER " + user);
sendOut("PASS " + pass);
success = true;
System.out.println("Waiting for response");
String response = in.readLine();
System.out.println(response);
}
catch(Exception e){
System.out.println("Login Failure");
success = false;
}
return(success);
}
public void sendOut(String command) throws Exception{
if (sk == null){
throw new Exception("Client is not connected!");
}
try{
out.write(command + "\r\n");
out.flush();
}
catch(Exception e){
System.out.println(e);
}
}
}在Java中與java.net - 連接創建FTP客戶端被拒絕:連接
你好,我寫了這個代碼,客戶端嘗試使用FTP連接連接和登錄到服務器。但是,我不斷收到此錯誤消息, java.net.ConnectException:連接被拒絕:連接 有人可以幫我嗎?
ftp是端口21 ssh是22 – user993553
我看到我會再試一次。 – Dan
現在它告訴我「連接被拒絕:連接」 – Dan