Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. package base;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.BufferedOutputStream;
  5. import java.io.ByteArrayInputStream;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import org.apache.commons.net.PrintCommandListener;
  9. import org.apache.commons.net.ftp.FTP;
  10. import org.apache.commons.net.ftp.FTPConnectionClosedException;
  11. import org.apache.commons.net.ftp.FTPReply;
  12. import org.apache.commons.net.ftp.FTPSClient;
  13. import com.ibm.jzos.ZFile;
  14.  
  15. public class FTPSVB {
  16.  
  17. public static void main(String[] args) {
  18. BufferedInputStream binp=null;
  19. BufferedOutputStream bout=null;
  20.  
  21. String server, username, password, fileTgt, fileSrc;
  22. String protocol = "TLS"; // SSL/TLS
  23. FTPSClient ftps = new FTPSClient(protocol);
  24. FTPSClient ftps2 = new FTPSClient(protocol);
  25. server="***";
  26. username="***";
  27. password="***";
  28. fileSrc="ABC00T.SMP.SAVE.ULRL";
  29. fileTgt="ABC00T.SMP.SAVE.OUT.ULRL";
  30. try
  31. {
  32. int reply;
  33. ftps.connect(server);
  34. ftps2.connect(server);
  35. reply = ftps.getReplyCode();
  36. reply = ftps2.getReplyCode();
  37. }
  38. try
  39. {
  40. ftps.setBufferSize(200);
  41. ftps.setFileType(FTP.BINARY_FILE_TYPE);
  42. if (!ftps.login(username, password))
  43. {
  44. ftps.logout();
  45. System.out.println("ERROR..");
  46. System.exit(-1);
  47. }
  48. ftps.execPBSZ(0);
  49. ftps.execPROT("P");
  50.  
  51. ftps.enterLocalPassiveMode();
  52. ftps.setAutodetectUTF8(true);
  53. ftps.site("QUOTE RDW");
  54. ftps2.setBufferSize(200);
  55. ftps2.setFileType(FTP.BINARY_FILE_TYPE);
  56. ftps2.site("QUOTE RDW");
  57. ftps2.site("QUOTE recfm=VB lrecl=106 blksize=27998");
  58. if (!ftps2.login(username, password))
  59. {
  60. ftps2.logout();
  61. System.out.println("ERROR..");
  62. System.exit(-1);
  63. }
  64. ftps2.execPBSZ(0);
  65. ftps2.execPROT("P");
  66. ftps2.enterLocalPassiveMode();
  67. ftps2.setAutodetectUTF8(true);
  68. binp=new BufferedInputStream(ftps.retrieveFileStream(fileSrc));
  69. bout=new BufferedOutputStream(ftps2.storeFileStream(fileTgt));
  70. final byte []bufLen= new byte[4];
  71. int readLen=binp.read(bufLen, 0, 4);// Read len
  72. int recCounter=1;
  73. while(readLen!=-1){
  74. ByteArrayInputStream ba2=new ByteArrayInputStream (bufLen,0,4);
  75. int z=ba2.read();
  76. int reclen=0;
  77. int li=0;
  78. while(z!=-1){
  79. if(li==0)
  80. reclen+=z*256;
  81. else if(li==1)
  82. reclen+=z;
  83. li++;
  84. z=ba2.read();
  85. }
  86. ba2.close();
  87. reclen-=4;
  88. byte []buf=new byte[reclen];
  89. readLen=binp.read(buf, 0, reclen);
  90. boolean isEOF=false;
  91. while(readLen<reclen) {
  92. int nextLen=binp.read(buf, readLen, reclen-readLen);
  93. if(nextLen==-1){// End of file is reached.
  94. isEOF=true;
  95. break;
  96. }
  97. readLen=readLen+nextLen;
  98. }
  99. String a=new String(buf, ZFile.DEFAULT_EBCDIC_CODE_PAGE);
  100. StringBuilder str=new StringBuilder(a);
  101. //str.append(System.getProperty("line.separator"));
  102. System.out.println(""+str);
  103. //appending extra space for record till its length matches file record length
  104. if(str.length()<102) {
  105. for (int i = str.length(); i < 102; i++) {
  106. str.append(" ");
  107. }
  108. }
  109. byte []outBytes=new byte[102];
  110. outBytes=str.toString().getBytes(ZFile.DEFAULT_EBCDIC_CODE_PAGE);
  111. bout.write(outBytes);
  112. if(isEOF){
  113. break;
  114. }
  115. readLen=binp.read(bufLen, 0, 4);// Read length- RDW
  116. recCounter++;
  117. }
  118. bout.flush();
  119. bout.close();
  120. binp.close();
  121. ftps.completePendingCommand();
  122. ftps2.completePendingCommand();
  123. ftps.logout();
  124. }
  125. catch (FTPConnectionClosedException e)
  126. {
  127. System.err.println("Server closed connection.");
  128. e.printStackTrace();
  129. }
  130. catch (IOException e)
  131. {
  132. e.printStackTrace();
  133. }
  134. finally
  135. {
  136. if (ftps.isConnected())
  137. {
  138. try
  139. {
  140. ftps.disconnect();
  141. }
  142. catch (IOException f)
  143. {
  144. // do nothing
  145. f.printStackTrace();
  146. }
  147. }
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement