java怎么拉取ftp域名地址上面的文件,目前是用链接ip的方式,但是链接域名地址事是链接不上的
使用jsch测试,把host中的ip改为域名可以正常访问:
public void login() {
JSch jsch = new JSch();
try {
if (privateKey != null) {
//设置登陆主机的秘钥
jsch.addIdentity(privateKey);
}
host = "www.vm-master.com";
//采用指定的端口连接服务器
session = jsch.getSession(username, host, port);
if (password != null) {
//设置登陆主机的密码
session.setPassword(password);
}
session.setConfig("PreferredAuthentications", "password");
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
//创建sftp通信通道
Channel channel = session.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;
System.out.println("sftp server connect success !!");
} catch (JSchException e) {
e.printStackTrace();
}
}
控制台: