問題我正在嘗試使用 Apache Commons VFS 從遠程桌面將文件上傳到 SFTP 服務器。連接已正確建立,但是當我將文件復制到服務器時拋出異常:代碼我編寫了負責根據此答案中的代碼將文件上傳到 SFTP 服務器的代碼。這是我的代碼:有很多日志,因為我不知道如何在遠程桌面上調試此代碼,所以我使用日志來代替它。當我從其他源接收文件并且我需要立即將此文件發送到 SFTP 服務器時,會調用此函數(這就是我使用字節數組作為輸入參數的原因)。氣缸ID應該是文件名 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(); } 對于如何修復此錯誤的建議,我將不勝感激。
1 回答

暮色呼如
TA貢獻1853條經驗 獲得超9個贊
我對 VFS 沒什么經驗,但這看起來很可疑:
manager.addProvider("sftp", new DefaultLocalFileProvider());
我想應該是:
manager.addProvider("sftp", new SftpFileProvider());
添加回答
舉報
0/150
提交
取消