leocoder0 opened a new issue, #332:
URL: https://github.com/apache/mina-sshd/issues/332

   ### Version
   
   sshd-sftp 2.9.2
   
   ### Bug description
   
   The sftp failed to recursively create a remote directory, but the directory 
was successfully created!
   
   ` 
   private void createRemoteDirectories(SftpClient sftp, String remoteDir) 
throws IOException {
           try {
               SftpClient.Attributes attrs = sftp.stat(remoteDir);
               ValidateUtils.checkTrue(attrs.isDirectory(), "Remote path 
already exists but is not a directory: %s",
                       remoteDir);
           } catch (SftpException e) {
               if (e.getStatus() == SftpConstants.SSH_FX_NO_SUCH_FILE) {
                   String[] items = 
remoteDir.substring(1).split(File.separator);
                   String tempPath = File.separator;
                   for (String item : items) {
                       tempPath += item + File.separator;
                       try {
                           SftpClient.Attributes attrs = sftp.stat(tempPath);
                           ValidateUtils.checkTrue(attrs.isDirectory(), "Remote 
path already exists but is not a directory: %s",
                                   tempPath);
                       } catch (SftpException ex) {
                           if (ex.getStatus() == 
SftpConstants.SSH_FX_NO_SUCH_FILE) {
                               logger.info("mkdir {}", tempPath);
                               **sftp.mkdir(tempPath);**
                           } else {
                               throw ex;
                           }
                       }
                   }
               }
           }
       }
   `
   
   ### Actual behavior
   
   The directory was created successfully but an exception was thrown!
   
   ### Expected behavior
   
   The directory was successfully created with no exceptions!
   
   ### Relevant log output
   
   ```Shell
   2023-03-14 10:48:45.958 [main] INFO  
com.leo.sftp.client.DefaultSftpClientImpl - mkdir /bbb/
   Exception in thread "main" SFTP error (SSH_FX_FAILURE): General failure
        at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.throwStatusException(AbstractSftpClient.java:217)
        at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.checkResponseStatus(AbstractSftpClient.java:212)
        at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.checkResponseStatus(AbstractSftpClient.java:186)
        at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.checkCommandStatus(AbstractSftpClient.java:164)
        at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.mkdir(AbstractSftpClient.java:802)
        at 
com.leo.sftp.client.DefaultSftpClientImpl.createRemoteDirectories(DefaultSftpClientImpl.java:335)
        at 
com.leo.sftp.client.DefaultSftpClientImpl.putFile(DefaultSftpClientImpl.java:243)
        at 
com.leo.sftp.client.DefaultSftpClientImpl.put(DefaultSftpClientImpl.java:219)
        at 
com.leo.sftp.client.DefaultSftpClientImpl.put(DefaultSftpClientImpl.java:186)
        at 
com.leo.sftp.client.DefaultSftpClientImpl.put(DefaultSftpClientImpl.java:179)
        at com.leo.sftp.client.SftpClientMain.main(SftpClientMain.java:83)
   ```
   
   
   ### Other information
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to