Tôi đang tạo nhiều đối tượng (Phiên) khác nhau chuyển thông tin xác thực đăng nhập vào một lớp java từ gói Oracle pl/sql. Sau đó tôi lưu trữ các đối tượng (Session) này trong Vector. Ý tưởng là để kết nối, mở các kênh cần thiết, đóng các kênh và cuối cùng ngắt kết nối một phiên cụ thể từ Vector này. Tôi quản lý để làm điều đó nhưng nó hoạt động chỉ một lần cho mỗi kết nối. Tôi có nghĩa là, trong Vector tôi có (session1, session2, session3), khi tôi gọi session1.connect() và sau đó session1.disconnect(), tôi không còn có thể gọi session1.connect() nữa, vì dường như nó cố gắng để kết nối đến máy chủ nhưng sau đó tôi nhận được:Jsch Cách sử dụng lại phiên
lấy phiên lưu trong Vector tôi mở một phiên họp và nhận được:
INFO: Connecting to sftp.myserver.com port 2122
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_4.7
INFO: Local version string: SSH-2.0-JSCH-0.1.48
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128- cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available.
INFO: CheckKexes: diffie-hellman-group14-sha1
INFO: diffie-hellman-group14-sha1 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange- sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
INFO: kex: server: ssh-rsa,ssh-dss
INFO: kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
INFO: kex: server: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
INFO: kex: server: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
INFO: kex: server: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
INFO: kex: server: none,[email protected]
INFO: kex: server: none,[email protected]
INFO: kex: server:
INFO: kex: server:
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
INFO: kex: client: ssh-rsa,ssh-dss
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
INFO: kex: client: none
INFO: kex: client: none
INFO: kex: client:
INFO: kex: client:
INFO: kex: server->client aes128-ctr hmac-md5 none
INFO: kex: client->server aes128-ctr hmac-md5 none
INFO: SSH_MSG_KEXDH_INIT sent
INFO: expecting SSH_MSG_KEXDH_REPLY
INFO: ssh_rsa_verify: signature true
WARN: Permanently added 'sftp.myserver.com' (RSA) to the list of known hosts.
INFO: SSH_MSG_NEWKEYS sent
INFO: SSH_MSG_NEWKEYS received
INFO: SSH_MSG_SERVICE_REQUEST sent
INFO: SSH_MSG_SERVICE_ACCEPT received
INFO: Authentications that can continue: publickey,keyboard-interactive,password
INFO: Next authentication method: publickey
INFO: Authentications that can continue: password
INFO: Next authentication method: password
INFO: Authentication succeeded (password).
INFO: Disconnecting from sftp.myserver.com port 2122
Tất cả mọi thứ đã làm việc tốt và cuối cùng tôi bị ngắt kết nối session1.
Sau đó, khi tôi cố gắng sử dụng session1 một lần nữa tôi nhận được ngoại lệ sau đây ...
INFO: Connecting to sftp.myserver.com port 2122
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_4.7
INFO: Local version string: SSH-2.0-JSCH-0.1.48
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available.
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available.
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available.
INFO: CheckKexes: diffie-hellman-group14-sha1
INFO: diffie-hellman-group14-sha1 is not available.
INFO: SSH_MSG_KEXINIT sent
INFO: Disconnecting from sftp.myserver.com port 2122
com.jcraft.jsch.JSchException: Packet corrupt
at com.jcraft.jsch.Session.start_discard(Session.java:994)
at com.jcraft.jsch.Session.read(Session.java)
at com.jcraft.jsch.Session.connect(Session.java:288)
at com.jcraft.jsch.Session.connect(Session.java:162)
at sftp.make_dir(SFTP:118)
Tôi có làm điều gì sai trong cách tôi cố gắng tái sử dụng các đối tượng java (Session)?
Cảm ơn rất nhiều sự giúp đỡ của bạn
Luca
Cảm ơn bạn đã giải thích @tushmish! Xin lỗi vì sự chậm trễ trong việc đánh dấu điều này như một giải pháp. Tại thời điểm đó, "workaround" của tôi đã tạo ra một nhóm tùy chỉnh của đối tượng Sessions được lưu trữ trong ArrayList và sau đó xử lý chúng. Không thanh lịch tôi biết, nhưng làm việc cho những gì tôi phải làm. – Luca