【发布时间】: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