SftpClient is producing diffent file size
Andre Charbonneau <[email protected]>
| Newsgroups | gmane.comp.java.sshtools.user |
|---|---|
| Message-ID | <[email protected]> |
Greetings,
While browsing the mailing list archives, I found the following message:
> Hi,
>
> I am using the latest J2SSH. I have the following code segment
>
>
> properties.setHost(hostName2);
> properties.setPrefPublicKey("ssh-dss");
> ssh.connect(properties, new IgnoreHostKeyVerification());
> pwd = new PasswordAuthenticationClient();
> pwd.setUsername(userName2);
> pwd.setPassword(password2);
> // Try the authentication
> result = ssh.authenticate(pwd);
> // Evaluate the result
> if (result == AuthenticationProtocolState.COMPLETE) {
> // The connection is authenticated we can now do some real
> work!
> SessionChannelClient session = ssh.openSessionChannel();
> session.executeCommand("find " + asDirectory2 + " -type f
> -exec md5sum {} \\; > " + hostName2 + "_orafiles.lst");
> SftpClient sftp = ssh.openSftpClient();
> sftp.lcd("/home/" + userName2);
> sftp.get(hostName2 + "_orafiles.lst");
> sftp.quit();
> ssh.disconnect();
>
> This code is successfully creating the file on the remote server and
> ftp'ing
> back to my local server. But the file size is always different from
> one run
> to another even though on the remote server, the file size always
> stays the
> same.
>
> Any ideas?
>
> Thanks so much,
>
> Mustafa
I think the problem in the above code is because the executeCommand()
method returns immediatly, as opposed to returning when the remote
command is actually done. What is needed in the above code is a piece
of code that will wait for the remote command to finish, such as:
try
{
sessionChannel.getState().waitForState(ChannelState.CHANNEL_CLOSED);
}
catch (InterruptedException ex)
{
JOptionPane.showMessageDialog(null,
"The command was interrupted!",
"Interrupted Exception",
JOptionPane.OK_OPTION);
}
Putting this piece of code before the sftp code should fix the problem.
Hope this helps...
Regards,
Andre
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/