問題我正在嘗試使用 Apache Commons VFS 從遠(yuǎn)程桌面將文件上傳到 SFTP 服務(wù)器。連接已正確建立,但是當(dāng)我將文件復(fù)制到服務(wù)器時(shí)拋出異常:代碼我編寫了負(fù)責(zé)根據(jù)此答案中的代碼將文件上傳到 SFTP 服務(wù)器的代碼。這是我的代碼:有很多日志,因?yàn)槲也恢廊绾卧谶h(yuǎn)程桌面上調(diào)試此代碼,所以我使用日志來代替它。當(dāng)我從其他源接收文件并且我需要立即將此文件發(fā)送到 SFTP 服務(wù)器時(shí),會調(diào)用此函數(shù)(這就是我使用字節(jié)數(shù)組作為輸入?yún)?shù)的原因)。氣缸ID應(yīng)該是文件名 private int uploadFileToSFTPServer(String cylinderId, byte[] documentContent, URI locationURI) { StandardFileSystemManager manager = new StandardFileSystemManager(); try { manager.addProvider("sftp", new DefaultLocalFileProvider()); final String hostName = locationURI.toString(); final String remoteFilePath = "IASD/EXR3_U5/" + cylinderId + ".txt"; LogHandler.log(LOGGER_NAME, LogLevel.DEBUG, "Remote Path: " + remoteFilePath); InputStream inStream = new ByteArrayInputStream(documentContent); String localPath = "E:\\SavedDocument\\TemporarySavedDocs\\" + cylinderId + ".txt"; try { LogHandler.log(LOGGER_NAME, LogLevel.DEBUG, "Local path:" + localPath); Files.copy(inStream, Paths.get(localPath)); } catch (Exception e) { LogHandler.log(LOGGER_NAME, LogLevel.WARN, "Exception while creating the file on local:" + e.getMessage()); } final String loginFTP = lindeCustomServiceConfig.getValueForConfigKey( LindeCustomServiceConfigurationKeys.csLoginFTP, "admin"); final String passwordFTP = lindeCustomServiceConfig.getValueForConfigKey( LindeCustomServiceConfigurationKeys.csPasswordFTP, "admin"); LogHandler.log(LOGGER_NAME, LogLevel.DEBUG, "FTP user login:" + loginFTP); LogHandler.log(LOGGER_NAME, LogLevel.DEBUG, "FTP user password: " + passwordFTP); manager.init(); } 對于如何修復(fù)此錯誤的建議,我將不勝感激。
如何修復(fù)使用 Apache Commons VFS 將文件上傳到 SFTP 服務(wù)器時(shí)發(fā)生的錯誤
揚(yáng)帆大魚
2023-12-13 16:37:21