为了账号安全,请及时绑定邮箱和手机立即绑定

如何修复使用 Apache Commons VFS 将文件上传到 SFTP 服务器时发生的错误

如何修复使用 Apache Commons VFS 将文件上传到 SFTP 服务器时发生的错误

扬帆大鱼 2023-12-13 16:37:21
问题我正在尝试使用 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());


查看完整回答
反对 回复 2023-12-13
  • 1 回答
  • 0 关注
  • 61 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信