Skip to content

Commit ce25934

Browse files
committed
Check and Create parent directory before uploading files
1 parent a9c6b96 commit ce25934

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/embulk/output/sftp/SftpFileOutput.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,15 @@ private FileObject newSftpFile(URI sftpUri)
216216
int count = 0;
217217
while (true) {
218218
try {
219-
return manager.resolveFile(sftpUri.toString(), fsOptions);
219+
FileObject file = manager.resolveFile(sftpUri.toString(), fsOptions);
220+
if (file.getParent().exists()) {
221+
logger.info("parent directory {} exists there", file.getParent());
222+
return file;
223+
}
224+
else {
225+
logger.info("trying to create parent directory {}", file.getParent());
226+
file.getParent().createFolder();
227+
}
220228
}
221229
catch (FileSystemException e) {
222230
if (++count == maxConnectionRetry) {

0 commit comments

Comments
 (0)