第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

關(guān)于使用jsch 上傳文件到sftp的問(wèn)題 java.lang.StringIndexOutOfBoundsException

關(guān)于使用jsch 上傳文件到sftp的問(wèn)題 java.lang.StringIndexOutOfBoundsException

拉風(fēng)的咖菲貓 2019-03-01 10:35:01
直接貼代碼了public class SftpUtil { private static Session session = null; private static Channel channel = null; private static final Logger log = Logger.getLogger(SftpUtil.class.getName()); /** * 獲取ChannelSftp實(shí)例對(duì)象 * * @param sftpDetails * @param timeout * @return ChannelSftp * @throws JSchException */ private static ChannelSftp getChannel(int timeout) throws JSchException { ResourceBundle bundle = ResourceBundle.getBundle("ZJW"); String ftpHost = bundle.getString(SftpConstants.SFTP_REQ_HOST); String port = bundle.getString(SftpConstants.SFTP_REQ_PORT); String ftpUsername = bundle.getString(SftpConstants.SFTP_REQ_USERNAME); String ftpPassword = bundle.getString(SftpConstants.SFTP_REQ_PASSWORD); int ftpPort = SftpConstants.SFTP_DEFAULT_PORT; if (port != null && !port.equals("")) { ftpPort = Integer.valueOf(port); } JSch jsch = new JSch(); // 創(chuàng)建JSch對(duì)象 session = jsch.getSession(ftpUsername, ftpHost, ftpPort); // 根據(jù)用戶名,主機(jī)ip,端口獲取一個(gè)Session對(duì)象 System.out.println(ftpUsername+"###"+ftpHost+"###"+ftpPort+"###"+ftpPassword); log.info("Session created."); if (ftpPassword != null) { session.setPassword(ftpPassword); // 設(shè)置密碼 } Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); //config.put("PreferredAuthentications", "password"); session.setConfig(config); // 為Session對(duì)象設(shè)置properties session.setTimeout(timeout); // 設(shè)置timeout時(shí)間 log.info("Session建立連接。。。"); session.connect(); // 通過(guò)Session建立鏈接 log.info("Session connected."); log.info("Opening Channel."); channel = session.openChannel("sftp"); // 打開(kāi)SFTP通道 channel.connect(); // 建立SFTP通道的連接 log.info("Connected successfully to ftpHost = " + ftpHost + ",as ftpUsername = " + ftpUsername + ", returning: " + channel); return (ChannelSftp) channel; } /** * zip文件上傳 * @param dst * @param src * @param timeout * @description dst為目標(biāo)文件名(e.g:xxx/sftp/xxx.zip") * src為本地文件名(e.g:c:\\xxx\\xxx.zip) * timeout為連接超時(shí)時(shí)間,單位ms */ public static void uploadZip(String dst,String src,int timeout){ try { ChannelSftp channel = getChannel(timeout); //獲取執(zhí)行對(duì)象 if(channel==null){ log.info("程序錯(cuò)誤,ChannelSftp獲取為null!"); } log.info("zip上傳開(kāi)始..."); channel.put(src, dst, ChannelSftp.OVERWRITE); //執(zhí)行sftp上傳,模式為overwrite log.info("zip上傳成功..."); } catch (Exception e) { log.info("系統(tǒng)異常,文件上傳失??!"); e.printStackTrace(); }finally { try { closeChannel(); } catch (Exception e) { log.info("系統(tǒng)異常,資源關(guān)閉失敗!"); e.printStackTrace(); } } } } 在本機(jī)裝了一個(gè)msftpsrvr64模擬sftp,使用FlashFXP連接上傳都很正常用自己寫的測(cè)試就不行了 @Test public void demo03(){ String dst = "\0000.zip"; String src = "D:\\0000.zip"; SftpUtil.uploadZip(dst, src, 6000); } 錯(cuò)誤碼: java.lang.StringIndexOutOfBoundsException: String index out of range: 16777219 at java.lang.String.checkBounds(Unknown Source) at java.lang.String.<init>(Unknown Source) at com.jcraft.jsch.Util.byte2str(Util.java:417) at com.jcraft.jsch.Util.byte2str(Util.java:428) at com.jcraft.jsch.DHG14.next(DHG14.java:203) at com.jcraft.jsch.Session.connect(Session.java:326) at com.jcraft.jsch.Session.connect(Session.java:183) at com.waterelephant.zjw.utils.SftpUtil.getChannel(SftpUtil.java:67) at com.waterelephant.zjw.utils.SftpUtil.uploadZip(SftpUtil.java:102) at com.waterelephant.test.PropTest.demo03(PropTest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 調(diào)試過(guò) 是在session.connect()那里出的異常 debug進(jìn)去看了一下 是連上了的 但是中間出了異常 沒(méi)看太懂...
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

是msftpsrvr64這個(gè)軟件的問(wèn)題 換了一個(gè)freeSSHD模擬sftp服務(wù)器就好了
連接成功之后上傳文件的時(shí)候又報(bào)了如下異常:
3: Permission denied
問(wèn)題原因:服務(wù)器的根目錄默認(rèn)C盤
解決:修改服務(wù)器目錄到D:XXX 即可解決問(wèn)題

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 1 回答
  • 0 關(guān)注
  • 2466 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)