Trying to replicate IBM Mainframe SFTP upload with JSch ChannelSftp -


i trying use jsch sftp channel upload file ibm mainframe, , directory has "//", mainframe automatically route file needs go.

in sftp command session on ibm mainframe, can this:

sftp myuser@1.2.3.4 connecting 1.2.3.4... myuser@1.2.3.4's password: sftp> pwd remote working directory: /users/home/myuser sftp> cd // sftp> pwd remote working directory: // sftp> put "#12345.abcdef.xxx.xxx" uploading #12345.abcdef.xxx.xxx //#12345.abcdef.xxx.xxx #12345.abcdef.xxx.xxx               100%  403   0.4kb/s 00:00 

so created jsch sftp session (version 0.1.5.1) attempt same upload, not work:

jsch jsch = new jsch(); session session = jsch.getsession("myuser", "1.2.3.4"); session.setpassword("mypass"); session.connect(); channel channel = session.openchannel("sftp"); channel.connect();  channelsftp sftp = (channelsftp)channel; log.info(" user home pwd " + sftp.pwd());  //prints /users/home/myuser sftp.cd("//") log.info(" pwd after cd " + sftp.pwd()); //only prints / sftp.put(filename);   //get sftp error, no such file 

so cannot // structure through jsch library. there mode or flag needs set sftp session know it's on mainframe?

i have no issue @ doing jsch sftp session /users/home/myuser directory, can't go //

try without calling channelsftp.cd():

channelsftp sftp = (channelsftp)channel; sftp.put("//" + filename);  // put //#12345.abcdef.xxx.xxx 

the sftp protocol doesn't have chdir-type operation. @ protocol level, pathnames don't start "/" interpreted relative directory sftp session started. there's no protocol command change starting directory.

sftp clients, including jsch, emulate chdir-like behavior client-side. when call channelsftp.cd(), jsch stores new remote directory locally. when later call put() or get(), , give pathname doesn't start "/", jsch prepends remote directory onto filename , passes altered name remote server.

i think what's happening jsch's chdir emulation being little clever. when call cd("//"), it's collapsing "//" single "/" , storing that. call put() relative pathname, it's prepending single "/" instead of double "//" want.

based on inspecting the jsch source code, looks jsch never alters remote names start "/". if call put("//somefile"), jsch should use name specified as-is.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -