int responseFTP = clientFTP.getReplyCode();各メソッド呼び出しの後、サーバーはメッセージを返します。次のメソッドは、サーバーからのメッセージを表示します:
if (!reponseFTP.isPositiveCompletion(replyCode)) {
// 操作は失敗しました。サーバーは
//接続を拒否するか、
戻り操作を拒否します。
}
private static void serverresponse(FTPClient ftpClient) {ログイン、識別、検証を含む完全なコードは次のとおりです:
String[] responses = ftpClient.getReplyStrings();
if (answers != null &&answers.length >0) {
for (文字列応答: 応答) {
System.out.println("サーバー: " + 応答);
}
}
}
import java.io.IOException;コンパイルと実行:
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnectionLogin {
private static void serverresponse(FTPClient ftpClient) {
String[] responses = ftpClient.getReplyStrings();
if (answers != null &&answers.length >0) {
for (文字列応答: 応答) {
System.out.println("サーバー: " + 応答);
}
}
}
public static void main(String[] args) {
String server = "serveraddress";
int ポート = 21;
文字列 username = "username";
文字列 password = "password";
FTPClient ftpClient = new FTPClient();
{
ftpClient.connect(server, port);
serverresponse(ftpClient);
int response = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(response)) {
System.out.println("操作に失敗しました。サーバーの回答: " + answer);
return;
}
boolean status = ftpClient.login(username, password);
serverresponse(ftpClient);
if (!state) {
System.out.println("サーバーにアクセスできません");
return;
} else {
System.out.println("識別に成功しました");
}
} catch (IOException ex) {
System.out.println("接続中のエラーが検出されました");
例:printStackTrace();
}
}
}
SERVER: 220---------- Pure FTPd [privsep] へようこそ ----------
SERVER: 220-You are user number 31 of 500 allowed.
SERVER: 220-Local time is now 06:02.サーバーポート:21.
SERVER:220-これはプライベートシステムです-匿名ログインなし
SERVER:220非アクティブの3分間後に切断されます.
SERVER:230-OK。現在の制限ディレクトリは /
SERVER: 230-100 個のファイルを使用 (1%) - authorized: 10000 files
SERVER: 230 5217 Kbytes used (0%) - authorized: 1536000 Kb
Successful identification
Please disable your ad blocker and refresh the window to use this website.