Java 530用户无法使用FTPSClient登录
我们正在尝试使用与标准FTP客户端相同的凭据访问一个FTPS服务器。但是,当使用Java类Java 530用户无法使用FTPSClient登录,java,ssl,ftp,Java,Ssl,Ftp,我们正在尝试使用与标准FTP客户端相同的凭据访问一个FTPS服务器。但是,当使用Java类FTPSClient时,我们会收到错误消息: 530用户无法登录 没有别的了。到目前为止,我们有以下代码(示例简化): 上述代码为我们提供了以下日志消息: 220 Microsoft FTP Service AUTH TLS 234 AUTH command ok. Expecting TLS Negotiation. Connected to A_SERVER. HOST A_SERVER 220 Hos
FTPSClient
时,我们会收到错误消息:
530用户无法登录
没有别的了。到目前为止,我们有以下代码(示例简化):
上述代码为我们提供了以下日志消息:
220 Microsoft FTP Service
AUTH TLS
234 AUTH command ok. Expecting TLS Negotiation.
Connected to A_SERVER.
HOST A_SERVER
220 Host accepted.
USER A_USER
331 Password required for A_USER.
PASS A_PASS
530 User cannot log in.
530 User cannot log in.
QUIT
221 Goodbye.
同时,如果我们在FTP客户端(如FTP Voyager)中执行相同操作,我们将得到:
我们尝试过的一些故障排除:
- 将
从TLS更改为SSL,两者都会遇到相同的问题协议
- 添加命令ftps.sendCommand(“主机”,服务器)代码>。我们看到FTP客户端在登录之前运行了这个命令,没有这一行,我们反而得到了错误:
530应该是有效的主机名。
- 使用
,导致预期的FTPClient
534策略需要SSL。
- 删除
ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager())代码>这会导致相同的错误
- 不设置主机,而是将用户用作:
username=“A_SERVER | A_user”代码>。相同的错误消息
TrustManager
设置为接受所有。是否还有其他设置需要注意
我们没有代理集,并且没有收到有用的错误消息。谷歌搜索530用户无法登录。
目前没有提供任何有用的信息。有人有什么建议吗
编辑
我使用另一个名为的包设法让它工作,但是如果有人能解释一下FTPSClient
为什么不工作,那就太好了。以下是工作代码:
public final class FTPSExample {
public static final void main(String[] args) {
boolean error = false;
String server, username, password;
FTPClient ftps;
server = "A_SERVER";
username = server + "|" + "A_USER";
password = "A_PASS";
ftps = new FTPClient();
ftps.setSecurity(FTPClient.SECURITY_FTPES);
ftps.addCommunicationListener(new FTPCommunicationListener() {
@Override
public void sent(String s) {
System.out.println(s);
}
@Override
public void received(String s) {
System.out.println(s);
}
});
try {
ftps.connect(server);
System.out.println("Connected to " + server + ".");
if (!ftps.isConnected()) {
ftps.disconnect(false);
System.err.println("FTP server refused connection.");
} else {
//ftps.sendSiteCommand("HOST " + server);
ftps.login(username, password);
if (!ftps.isAuthenticated()) {
error = true;
} else {
System.out.println("Connected!");
}
ftps.logout();
}
}
catch (Exception e) {
if (ftps.isConnected()) {
try {
ftps.disconnect(false);
}
catch (Exception f) {
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
System.exit(1);
}
System.exit(error ? 1 : 0);
}
}
以及由此产生的数据:
220 Microsoft FTP Service
Connected to A_SERVER.
AUTH TLS
234 AUTH command ok. Expecting TLS Negotiation.
USER A_SERVER|A_USER
331 Password required for A_SERVER|A_USER.
PASS A_PASS
230 User logged in.
我记得,当我试图将代码从FTP更改为FTPS时,我遇到了相同的错误,我使用以下代码解决了这个问题:
public void FTPSUploader(String host, String user, String pwd,int numPort) throws Exception {
FTPSClient ftp = new FTPSClient();
ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftps.connect(host, numPort);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftps.disconnect();
throw new Exception("Exception in connecting to FTPs Server");
}
ftps.login(user, pwd);
ftps.setFileType(FTP.BINARY_FILE_TYPE);
ftps.enterLocalPassiveMode();
ftps.execPBSZ(0);// Set protection buffer size
ftps.execPROT("P");// Set data channel protection to private--
}
如果您在服务器上禁用TLS/SSL要求,您可以使用
FTPClient
登录吗?将尝试一下,尽管目前无法访问,因此需要一些时间。嗯,我刚刚尝试了一个不同于FTPClient
的包,并使其正常工作。因此,使用相同的设置是可行的。这很奇怪…在下面的答案中,保护缓冲区大小和通道保护线是重要的。这很可能是你的问题。ftps.execPBSZ(0);//设置保护缓冲区大小ftps.execPROT(“P”);//将数据通道保护设置为私有--在登录之前设置标志,ftps.execPBSZ(0)代码>和ftps.execPROT(“P”)代码>修复了该问题。谢谢你。
220 Microsoft FTP Service
Connected to A_SERVER.
AUTH TLS
234 AUTH command ok. Expecting TLS Negotiation.
USER A_SERVER|A_USER
331 Password required for A_SERVER|A_USER.
PASS A_PASS
230 User logged in.
public void FTPSUploader(String host, String user, String pwd,int numPort) throws Exception {
FTPSClient ftp = new FTPSClient();
ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftps.connect(host, numPort);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftps.disconnect();
throw new Exception("Exception in connecting to FTPs Server");
}
ftps.login(user, pwd);
ftps.setFileType(FTP.BINARY_FILE_TYPE);
ftps.enterLocalPassiveMode();
ftps.execPBSZ(0);// Set protection buffer size
ftps.execPROT("P");// Set data channel protection to private--
}