Skip to content

Commit

Permalink
enhance copy. make replace-files work for sftp, except sftp to sftp y…
Browse files Browse the repository at this point in the history
…et. fix dest is null. gui move ssh fields to top for more room. put couple util methods in sftp.
  • Loading branch information
stan committed Apr 1, 2018
1 parent f1b45a6 commit a30e7a1
Show file tree
Hide file tree
Showing 9 changed files with 6,366 additions and 6,250 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ nbbuild/
dist/
nbdist/
.nb-gradle/
/.project
715 changes: 360 additions & 355 deletions JFileProcessor-Sdk/src/main/java/com/towianski/jfileprocessor/Copier.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,251 changes: 625 additions & 626 deletions JFileProcessor-Sdk/src/main/java/com/towianski/jfileprocessor/CopyFrame.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8,345 changes: 4,211 additions & 4,134 deletions JFileProcessor-Sdk/src/main/java/com/towianski/jfileprocessor/JFileFinderWin.java

Large diffs are not rendered by default.

Expand Up @@ -45,7 +45,7 @@ public void close()
public void sftpIfDiff( String locFile, String user, String password, String rhost, String rmtFile )
{
Sftp sftp = new Sftp( user, password, rhost );
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getSftp();
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getChanSftp();
boolean doCopy = false;

try {
Expand Down Expand Up @@ -363,7 +363,7 @@ public void copyTo( Session session, String lfile, String rfile )
public void SftpPut( String locFile, String user, String password, String rhost, String rmtFile )
{
Sftp sftp = new Sftp( user, password, rhost );
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getSftp();
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getChanSftp();

try {
// sftpChannel.put("C:/source/local/path/file.zip", "/target/remote/path/file.zip");
Expand All @@ -378,7 +378,7 @@ public void SftpPut( String locFile, String user, String password, String rhost,
public void SftpGet( String rmtFile, String user, String password, String rhost, String locFile )
{
Sftp sftp = new Sftp( user, password, rhost );
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getSftp();
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getChanSftp();

try {
System.out.println( "SftpGet rmtFile =" + rmtFile + "= to locFile =" + locFile + "=" );
Expand All @@ -393,7 +393,7 @@ public void SftpGet( String rmtFile, String user, String password, String rhost,
public long getRemoteFileSize( String lfile, String user, String password, String rhost, String filename )
{
Sftp sftp = new Sftp( user, password, rhost );
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getSftp();
com.jcraft.jsch.ChannelSftp chanSftp = sftp.getChanSftp();
SftpATTRS attrs = null;
long fsize = -1;

Expand Down
40 changes: 36 additions & 4 deletions JFileProcessor-Sdk/src/main/java/com/towianski/sshutils/Sftp.java
Expand Up @@ -8,7 +8,12 @@
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import com.towianski.jfileprocessor.CopierNonWalker;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
Expand All @@ -17,7 +22,7 @@
*/
public class Sftp {
JSch jsch=new JSch();
com.jcraft.jsch.ChannelSftp sftp = null;
com.jcraft.jsch.ChannelSftp chanSftp = null;
Channel channel = null;
Session session = null;

Expand Down Expand Up @@ -60,7 +65,7 @@ public Sftp( String user, String password, String rhost )

channel=session.openChannel( "sftp" );
channel.connect();
sftp = (com.jcraft.jsch.ChannelSftp)channel;
chanSftp = (com.jcraft.jsch.ChannelSftp)channel;
System.out.println( "Sftp done" );
}
catch(Exception e)
Expand All @@ -69,9 +74,36 @@ public Sftp( String user, String password, String rhost )
}
}

public com.jcraft.jsch.ChannelSftp getSftp()
public com.jcraft.jsch.ChannelSftp getChanSftp()
{
return sftp;
return chanSftp;
}

public boolean exists( String path )
{
try {
chanSftp.stat( path );
}
catch (SftpException ex)
{
Logger.getLogger(CopierNonWalker.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return true;
}

public boolean isDir( String path )
{
SftpATTRS sourceSftpAttrs = null;
try {
sourceSftpAttrs = chanSftp.stat( path );
}
catch (SftpException ex)
{
Logger.getLogger(CopierNonWalker.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
return sourceSftpAttrs.isDir();
}

public void close()
Expand Down

0 comments on commit a30e7a1

Please sign in to comment.