This content has been marked as final. Show 15 replies
Having spent significant time studying the SSH and SFTP protocol documents and implementing both an SSH client and server I'm pretty sure (but not certain without going through the documentation again) that there is nothing in the SFTP protocol that stops one appending a comma separated list of parameters to the remote file path. I'm also pretty sure that there is nothing in the JSCH SFTP client library that parses the remote file name so I don't see why one just can't append the parameters to the remote file name. Have you tried doing this?
Why are you being so mysterious about the server OS? It might help us help you if we knew which OS and which SSH server is being used.
P.S. Since you are able to perform the transfer using the command line you could always use Runtime.exec() or ProcessBuilder!
sabre150, thank you for your responce.
Unfortunatelly, adding a list of flags to remoteFile name does not work.
I get the same thing I been getting when I try to upload it without these flags:
ORA-29532: Java call terminated by uncaught Java exception: 4: java.io.InterruptedIOException: send() timed out
A non-blocking socket operation could not be completed immediately.
However, when I connect to sftp through putty, this command work normally...
Am i missing something?
Edited by: 997451 on 02.04.2013. 03.28
Since SFTP does not communicate directly with sockets but sits on top of SSH the implication of that exception is that the problem is with the SSH communication and not SFTP itself. Since it interests me, if I can find the time I will try to use JSCH to send a file with that peculiar file name construct to an openssh server. Of course you could make it easier for me to find the time by posting your Java code! This might also allow us to decide whether or not you are missing something!
Again, why are you so reluctant to publish which OS and which SSH server your are using? Surely it can't hurt to publish this information.
Edited by: sabre150 on Apr 2, 2013 12:37 PM
I have just transferred files with the added comma separated paramters using JSCH/SFTP version jsch-0.1.48 to an openssh server and to my own server and both produce the correct files on the server. This taken with your ability to send the files using Putty implies to me that you are using JSCH wrongly. Without seeing your code I have no way of being certain.
No, of course it cannot hurt :-)
OS is "Guardian".
I connect to it using java stored procedures, DB is oracle 10g.
The code is in several java stored procedures. In short I do this:
// inside class "SftpConnector", i build sftpChannel
public void buildChannelSftp
JSch jsch = new JSch();
session = jsch.getSession(sftpUser,sftpHost,sftpPort);
session.setConfig(sessionConfig); // StrictHostKeyChecking = "no"
session.setTimeout(sessionTimeout * 1000); // sessionTimeout = 0
channel = session.openChannel("sftp");
channelSftp = (ChannelSftp)channel;
later, in some other class:
...// I take built channel...
channelSftp.put(localFile, remoteFile, ChannelSftp.RESUME); // I also tried without ChannelSftp.RESUME
Edited by: 997451 on 02.04.2013. 05.00
Edited by: 997451 on 02.04.2013. 05.01
I have never used JSCH from stored procedure. I don't think you should be keeping open the JSch connection; at least until you have proved you can actually perform the transfer I think you should be opening the connection each time you want to do a transfer.
Why are you not trying this code outside of a stored procedure? If I were doing this I would create a class that I could test outside of a store procedure and then when I was sure it was working properly I would use it, without modifications, within the stored procedure.
997451 wrote:But you say "later, in some other class" !
I do create connection every time I transfer something.
After that I close it.
I cannot create standalone java app because I only have these resources, and I can only connect to sftp through DB ( network restrictions).Presumably on your development system you can install an 'openssh' server and then test basic functionality against that!
Did you find anything wrong with my source?You seem to do a lot more than I do and the fragmented nature of your code makes it difficult for me duplicate. You don't show the construction of 'sessionConfig' or 'known' hosts so I cannot use what you have to diagnose anything. Also, I use public key authentication rather than 'password' authentication.
gimbal2 wrote:I'm reluctant to do the OPs work for him; this forum is not a coding service and he is getting paid for this and I'm not. The line of code I use is simply
fair is fair dude - now I wonder why you are so reluctant to share your code :) I am really curious how you invoked the 'put' method to be able to claim this:
I have just transferred files with the added comma separated paramters using JSCH/SFTP version jsch-0.1.48 to an openssh server
which transfers a file on my laptop to a file on my server. I run an 'openssh' server on both my laptop and server.
channel.put(System.getProperty("user.home") + "/PIC-LIST.txt", "xxxxx.txt, 0, 16, 1080, 900");
There is just too much of code missing for me to turn the OPs code fragments into a representative SSCCE so if the OP wants me to help any further then he is going to have to create an SSCCE and post it.
gimbal2 wrote:SFTP is not in any way related to FTP and all I did was to look at the Javadoc for class ChannelSftp.
I believe that single line of code saves the day though; to be honest I wouldn't have considered trying that, I would have searched for a way to execute a low level FTP command like you can do with Apache commons.net; there doesn't seem to be one if I quickly glance over the javadoc.