Creating nested directories on server using JSch in Java

前端 未结 3 1662
谎友^
谎友^ 2020-12-11 10:35

I am making an application for file uploading in Java using jSch. I want to put my file in different directories based on their creation date etc.

I hav

3条回答
  •  青春惊慌失措
    2020-12-11 11:10

    Finally, I've done it.

    This is how I got succeed :

    try {
                channelTarget.put(get, completeBackupPath + fileName);
            } catch (SftpException e) {
                System.out.println("Creating Directory...");
                String[] complPath = completeBackupPath.split("/");
                channelTarget.cd("/");
                for (String dir : complPath) {
                    if (folder.length() > 0) {
                        try {
                            System.out.println("Current Dir : " + channelTarget.pwd());
                            channelTarget.cd(folder);
                        } catch (SftpException e2) {
                            channelTarget.mkdir(folder);
                            channelTarget.cd(folder);
                        }
                    }
                }
                channelTarget.cd("/");
                System.out.println("Current Dir : " + channelTarget.pwd());
                channelTarget.put(get, completeBackupPath + fileName);
            }
    

提交回复
热议问题