Hallo zusammen,
ich habe folgendes Problem:
Meine Java-Anwendung überträgt große Datenmengen per SFTP (ich nutze die JSch-Implementierung) auf einen FTP-Server. Auf diesem ist konfiguriert, dass nach 3600 Sekunden, oder nach 2GB transferierter Daten (je nachdem, was zuerst erreicht ist) ein "rekey" notwendig ist, also die Schlüssel erneut ausgetauscht werden sollen.
Dies bekomme ich allerdings momentan auf Clientenseite nicht mit. Es tritt für mich kein sichtbarer Fehler auf, sondern der Transfer bleibt einfach "hängen".
Gibt es eine Möglichkeit, festzustellen, dass der Server ein "rekey" verlangt? Wenn ja, wie?
Gruß,
Nick
ich habe folgendes Problem:
Meine Java-Anwendung überträgt große Datenmengen per SFTP (ich nutze die JSch-Implementierung) auf einen FTP-Server. Auf diesem ist konfiguriert, dass nach 3600 Sekunden, oder nach 2GB transferierter Daten (je nachdem, was zuerst erreicht ist) ein "rekey" notwendig ist, also die Schlüssel erneut ausgetauscht werden sollen.
Dies bekomme ich allerdings momentan auf Clientenseite nicht mit. Es tritt für mich kein sichtbarer Fehler auf, sondern der Transfer bleibt einfach "hängen".
Gibt es eine Möglichkeit, festzustellen, dass der Server ein "rekey" verlangt? Wenn ja, wie?
Gruß,
Nick
Java:
public class SftpClient
{
private static Logger logger = null;
private JSch jSch = null;
private Session sftpSession = null;
private ChannelSftp sftpChannel = null;
private int chunkSize = 16384; // default
private static final long MEGA_BYTE = 1024 * 1024;
private static final long BYTES_TO_LOG = MEGA_BYTE * 50; // 50MB
private boolean abort = false;
private boolean success = true;
private String host = null;
private int port = 22;
private String ftpSubdir = null;
private String username = null;
private String password = null;
public SftpClient( String host, int port, String username, String password, String ftpSubdir )
{
//...
}
public boolean connect( Long orderId )
{
try
{
this.jSch = new JSch();
logger.info( "[Order:" + orderId + "] Connecting to SFTP-Server: " + this.username + ":" + this.password + "@" + this.host + ":" + this.port );
// session herstellen
this.sftpSession = this.jSch.getSession( this.username, this.host, this.port );
// config aufbauen
Hashtable<String,String> config = new Hashtable<String,String>();
config.put( "StrictHostKeyChecking", "no" );
this.sftpSession.setConfig( config );
this.sftpSession.setPassword( this.password );
// Verbindung aufbauen
this.sftpSession.connect();
this.sftpChannel = ( ChannelSftp ) this.sftpSession.openChannel( "sftp" );
this.sftpChannel.connect();
logger.info( "[Order:" + orderId + "] Current directory on SFTP-Server (pwd): " + this.sftpChannel.pwd() );
if( this.ftpSubdir != null && this.ftpSubdir.length() > 0 )
{
logger.info( "[Order:" + orderId + "] Changing to subdirectory on SFTP-Server (cd): " + this.ftpSubdir );
this.sftpChannel.cd( this.ftpSubdir );
logger.info( "[Order:" + orderId + "] Current directory on SFTP-Server (pwd): " + this.sftpChannel.pwd() );
}
}
catch( JSchException e )
{
logger.error( "[Order:" + orderId + "] Error connecting to SFTP-Server... (uri: '" + this.sftpUri + "')", e );
return false;
}
catch( SftpException e )
{
logger.error( "[Order:" + orderId + "] Error connecting to SFTP-Server... (uri: '" + this.sftpUri + "')", e );
return false;
}
return this.sftpChannel.isConnected();
}
public void uploadSynchronized( String source, String target, Long filesize, Long orderId )
{
long overallFilesize = filesize == null ? 0 : filesize;
long overallUploadedBytes = 0;
long uploadedBytes = 0;
try
{
if( !checkIfFileExists( source ) )
{
OutputStream tOut = this.sftpChannel.put( target );
FileInputStream in = new FileInputStream( source );
byte[] bytes = new byte[ this.chunkSize ];
int count = in.read( bytes );
try
{
while( count != -1 && count <= this.chunkSize && !this.abort )
{
tOut.write( bytes, 0, count );
uploadedBytes = uploadedBytes + this.chunkSize;
if( uploadedBytes >= BYTES_TO_LOG )
{
overallUploadedBytes = overallUploadedBytes + uploadedBytes;
uploadedBytes = 0;
logger.info( "[Order:" + orderId + "] " + overallUploadedBytes / MEGA_BYTE + "MB of " + overallFilesize / MEGA_BYTE
+ "MB uploaded (source: '" + source + "', target: '" + target + "')" );
}
count = in.read( bytes );
}
}
finally
{
in.close();
tOut.close();
}
}
else
{
this.success = false;
logger.error( "[Order:" + orderId + "] Error uploading file... (source: '" + source + "', target: '" + target
+ "'): File already exists on SFTP-Server" );
}
}
catch( IOException e )
{
this.success = false;
logger.error( "[Order:" + orderId + "] Error uploading file... (source: '" + source + "', target: '" + target + "')", e );
}
catch( SftpException e )
{
this.success = false;
logger.error( "[Order:" + orderId + "] Error uploading file... (source: '" + source + "', target: '" + target + "')", e );
}
}