Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger ( philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package com.helger.webbasics.ssh.sftp;
 public final class WrapperChannelSftp
   private static final Logger s_aLogger = LoggerFactory.getLogger (WrapperChannelSftp.class);
   private WrapperChannelSftp ()

Upload a file to the server.

aSettings Connections settings to the server.
aRunnable The callback that performs the actions via SFTP. May not be null.
com.helger.commons.state.ESuccess.SUCCESS if operation succeeded, com.helger.commons.state.ESuccess.FAILURE otherwise.
com.jcraft.jsch.JSchException If some general connection handling stuff goes wrong.
   public static ESuccess execute (@Nonnull final IServerConnectionSettingsPassword aSettings,
                                   @Nonnull final IChannelSftpRunnable aRunnablethrows JSchException
     if (aRunnable == null)
       throw new NullPointerException ("runnable");
     Session aSession = null;
     Channel aChannel = null;
     ChannelSftp aSFTPChannel = null;
       // get session from pool
       aSession = SftpSessionFactory.createSession (aSettings);
       if (aSession == null)
         throw new IllegalStateException ("Failed to get session from pool");
       // Open the SFTP channel
       aChannel = aSession.openChannel ("sftp");
       aChannel.connect ();
       aSFTPChannel = (ChannelSftpaChannel;
       // call callback
       aRunnable.execute (aSFTPChannel);
       return .;
     catch (final SftpException ex)
       .error ("Error peforming SFTP action: " + aRunnable.getDisplayName (), ex);
       return .;
       // end SFTP session
       if (aSFTPChannel != null)
         aSFTPChannel.quit ();
       // close channel
       if (aChannel != null && aChannel.isConnected ())
         aChannel.disconnect ();
       // destroy session to the pool
       if (aSession != null)
         SftpSessionFactory.destroySession (aSession);
New to GrepCode? Check out our FAQ X