【问题标题】:VFS SFTP upload sending directory structure, not just fileVFS SFTP上传发送目录结构,不仅仅是文件
【发布时间】:2013-09-09 14:36:30
【问题描述】:

我正在尝试将文件上传到 SFTP 站点,但整个目录结构正在 SFTP 站点上重新创建,而不是仅在根目录上上传文件。我正在调用 sendSftp(见下文)。

public void sendSftp(String filename, IPropertyHelper ph) {
    def local = VFS.getManager().toFileObject(new File("${filename}"))
    def remote = VFS.getManager().resolveFile(buildSftpPath(filename, ph), new FileSystemOptions());
    remote.copyFrom(local, Selectors.SELECT_SELF) 
}

private String buildSftpPath(filename, IPropertyHelper ph) {
    return "sftp://${ph.properties.sftp_Login}:${ph.properties.sftp_Password}@${ph.properties.sftp_Hostname}/${filename}"
}

任何有关如何仅发送文件并将其放置在 SFTP 站点的根目录中的帮助都非常好,谢谢!

【问题讨论】:

  • def local = VFS.getManager().toFileObject(new File("${filename}")) 更改为def local = VFS.manager.resolveFile( filename ) 有帮助吗?
  • 同样的结果,发送整个目录结构。
  • 什么是filename?我怀疑buildSftpPath(filename, ph) 正在构建完整的目录结构...试试buildSftpPath(new File( filename ).name, ph)
  • 谢谢 tim_yates,这就是答案!
  • 作为答案添加 :-)

标签: groovy vfs apache-commons-vfs


【解决方案1】:

filename 是什么?我怀疑buildSftpPath(filename, ph) 正在构建完整的目录结构...试试buildSftpPath(new File( filename ).name, ph)

【讨论】:

    猜你喜欢
    • 2013-11-17
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 2018-02-26
    相关资源
    最近更新 更多