12:47:57 INFO [jsch] Connecting to XXX.XX.XX.XXX port 1222
12:47:57 INFO [jsch] Connection established
12:47:58 INFO [jsch] Remote version string: SSH-2.0-OpenSSH_5.3
12:47:58 INFO [jsch] Local version string: SSH-2.0-JSCH-0.1.52
12:47:58 INFO [jsch] CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256- cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
12:47:58 INFO [jsch] aes256-ctr is not available.
12:47:58 INFO [jsch] aes192-ctr is not available.
12:47:58 INFO [jsch] aes256-cbc is not available.
12:47:58 INFO [jsch] aes192-cbc is not available.
12:47:58 INFO [jsch] CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2- nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
12:47:58 INFO [jsch] diffie-hellman-group14-sha1 is not available.
12:47:58 INFO [jsch] CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
12:47:58 INFO [jsch] SSH_MSG_KEXINIT sent
12:47:58 INFO [jsch] SSH_MSG_KEXINIT received
12:47:58 INFO [jsch] kex: server: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
12:47:58 INFO [jsch] kex: server: ssh-rsa,ssh-dss
12:47:58 INFO [jsch] kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
12:47:58 INFO [jsch] kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
12:47:58 INFO [jsch] kex: server: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
12:47:58 INFO [jsch] kex: server: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
12:47:58 INFO [jsch] kex: server: none,zlib@openssh.com
12:47:58 INFO [jsch] kex: server: none,zlib@openssh.com
12:47:58 INFO [jsch] kex: server:
12:47:58 INFO [jsch] kex: server:
12:47:58 INFO [jsch] kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
12:47:58 INFO [jsch] kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
12:47:58 INFO [jsch] kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
12:47:58 INFO [jsch] kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
12:47:58 INFO [jsch] kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
12:47:58 INFO [jsch] kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96
12:47:58 INFO [jsch] kex: client: none
12:47:58 INFO [jsch] kex: client: none
12:47:58 INFO [jsch] kex: client:
12:47:58 INFO [jsch] kex: client:
12:47:58 INFO [jsch] kex: server->client aes128-ctr hmac-md5 none
12:47:58 INFO [jsch] kex: client->server aes128-ctr hmac-md5 none
12:47:58 INFO [jsch] SSH_MSG_KEXDH_INIT sent
12:47:58 INFO [jsch] expecting SSH_MSG_KEXDH_REPLY
12:47:58 INFO [jsch] ssh_rsa_verify: signature true
12:47:58 INFO [jsch] Host 'XXX.XX.XX.XXX' is known and matches the RSA host key
12:47:58 INFO [jsch] SSH_MSG_NEWKEYS sent
12:47:58 INFO [jsch] SSH_MSG_NEWKEYS received
12:47:58 INFO [jsch] SSH_MSG_SERVICE_REQUEST sent
12:47:59 INFO [jsch] SSH_MSG_SERVICE_ACCEPT received
12:47:59 DEBUG [DefaultSftpSessionFactory]
Warning! This is a private system. Unauthorized access to or use of
this system is strictly prohibited. By continuing, you acknowledge
your awareness of and concurrence with the CompanyABC's Acceptable Use
Policy. Unauthorized users may be subject to criminal and civil
prosecution under the law and are subject to disciplinary action under
CompanyABC policies.
12:47:59 INFO [jsch] Authentications that can continue: gssapi-with- mic,publickey,keyboard-interactive,password
12:47:59 INFO [jsch] Next authentication method: gssapi-with-mic
12:47:59 INFO [jsch] Authentications that can continue: publickey,keyboard-interactive,password
12:47:59 INFO [jsch] Next authentication method: publickey
12:48:00 INFO [jsch] Authentication succeeded (publickey).
12:48:01 DEBUG [SimplePool] Obtained new org.springframework.integration.sftp.session.SftpSession@46fdc558.
12:48:03 DEBUG [CachingSessionFactory] Releasing Session org.springframework.integration.sftp.session.SftpSession@46fdc558 back to the pool.
12:48:03 DEBUG [SimplePool] Removing org.springframework.integration.sftp.session.SftpSession@46fdc558 from the pool
12:48:03 INFO [jsch] Disconnecting from XXX.XX.XX.XXX port 1222
12:48:03 DEBUG [SftpInboundFileSynchronizer] 0 files transferred
12:48:03 INFO [jsch] Caught an exception, leaving main loop due to Socket Closed
12:48:03 DEBUG [SourcePollingChannelAdapter] Received no Message during the poll, returning 'false'
12:48:18 INFO [jsch] Connecting to XXX.XX.XX.XXX port 1222
以下是我正在使用的课程:
@Configuration
@MessageEndpoint
@EnableIntegration
@IntegrationComponentScan(basePackages = "com.dashboard")
@PropertySource(value = { "classpath:sftp-configuration.properties" })
public class SFTPConfiguration {
private static final Logger logger = LoggerFactory.getLogger(SFTPConfiguration.class);
@Autowired
private Environment environment;
@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory sFactory = new DefaultSftpSessionFactory(true);
//new DefaultSftpSessionFactory(true); don't know why to pass true in constructor.
sFactory.setHost(environment.getRequiredProperty("sftp.host"));
sFactory.setUser(environment.getRequiredProperty("sftp.user"));
// sFactory.setPassword(environment.getProperty("sftp.password"));
//sFactory.setHost(environment.getRequiredProperty("testHost"));
//sFactory.setUser(environment.getRequiredProperty("testUser"));
sFactory.setPort(Integer.parseInt(environment.getRequiredProperty("sftp.port")));
sFactory.setPrivateKey(environment.getRequiredProperty("sftp.privateKey", UrlResource.class));
sFactory.setPrivateKeyPassphrase(environment.getRequiredProperty("sftp.privateKeyPassphrase"));
// TODO: to allow unknow hosts, for production add a file with known hosts IP.
sFactory.setAllowUnknownKeys(Boolean.parseBoolean(environment.getRequiredProperty("sftp.allowUnknownKeys")));
sFactory.setTimeout(Integer.parseInt(environment.getRequiredProperty("sftp.timeout")));
// need to see if caching works as expected.
CachingSessionFactory<LsEntry> cacheSftpFactory = new CachingSessionFactory<LsEntry>(sFactory);
// below property value in milliseconds.
cacheSftpFactory.setSessionWaitTimeout(Integer.parseInt(environment.getRequiredProperty("sftp.sessionWaitTimeout")));
cacheSftpFactory.setPoolSize(Integer.parseInt(environment.getRequiredProperty("sftp.sessionCacheSize")));
return cacheSftpFactory;
}
//set preserve timestamp true
// Reversible File List filer
//TODO: preserve-timestamp
@Bean
public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
fileSynchronizer.setDeleteRemoteFiles(Boolean.parseBoolean(environment.getRequiredProperty("sftp.deleteRemoteFiles")));
fileSynchronizer.setRemoteDirectory(environment.getRequiredProperty("sftp.remoteDirectory"));
//fileSynchronizer.setRemoteDirectory(environment.getRequiredProperty("testRemoteDir"));
fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter(environment.getRequiredProperty("sftp.fileFilterPattern")));
return fileSynchronizer;
}
@Bean
@InboundChannelAdapter(value = "sftpChannel", poller = @Poller(fixedDelay = "30000"))
public MessageSource<File> sftpMessageSource() {
SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(
sftpInboundFileSynchronizer());
source.setLocalDirectory(new File(environment.getRequiredProperty("sftp.localDirectory")));
source.setAutoCreateLocalDirectory(true);
source.setLocalFilter(new AcceptOnceFileListFilter<File>());
//AcceptOnceFileListFilter -- AcceptAllFileListFilte
return source;
}
@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("SFTP-Payload-Mesage:"+message.getPayload());
}
};
}
}
以下是configuration.properties文件:
sftp.host = XXX.XX.XX.XXX
sftp.allowUnknownKeys=true
sftp.sessionCacheSize=2
sftp.sessionWaitTimeout=200000
sftp.deleteRemoteFiles=false
sftp.remoteDirectory=/home/fath/to/folder
sftp.fileFilterPattern=*.eot
sftp.localDirectory=D\:\\test-ftp
sftp.privateKey = file\Private.txt
sftp.timeout=60000
sftp.privateKey-Test=classpath\:META-INF/keys/sftpTest
sftp.privateKeyPassphrase = *******
sftp.port = 1222
sftp.user = XXXX
sftp.password =
我通过自己创建一个SFTP服务器来测试代码,它可以工作。但是对于生产它不会复制文件。我的理解是,对话(下文)引起了问题。如何关闭/接受或通过它?
12:47:59 DEBUG [DefaultSftpSessionFactory]
Warning! This is a private system. Unauthorized access to or use of
this system is strictly prohibited. By continuing, you acknowledge
your awareness of and concurrence with the CompanyABC's Acceptable Use
Policy. Unauthorized users may be subject to criminal and civil
prosecution under the law and are subject to disciplinary action under
CompanyABC policies.