2016-06-08 1 views
2

JSocket을 사용하여 SFTP를 통해 메인 프레임에 파일을 저장하려고합니다.JSch SFTP에서 IBM z/OS로 전송 실패 : 파일을 쓰지 못했습니다. 중첩 예외는 3입니다. 사용 권한이 거부되었습니다.

session = jsch.getSession(username, host, port); 
Properties config = getProperties(host, port); 
session.setConfig(config); 
... 
... 
protected Properties getProperties(String host, int port) throws JSchException { 
    Properties config = new Properties(); 
    config.put("StrictHostKeyChecking", strictHostChecking ? "yes" : "no"); 
    config.put("kex", "diffie-hellman-group-exchange-sha1"); 
    config.put("PreferredAuthentications", "password"); 
    return config; 
} 

세션 연결 괜찮 :

다음
public void uploadFile(String contents) throws Exception { 
    JSch.setLogger(new JSCHLogger()); 
    connectIfDisconected(); 
    LOGGER.info("Channel isConnected=: " + channel.isConnected()); 
    OutputStream os = channel.put("//!DTS4.UP.G5TB4.S60301"); 
    os.write(contents.getBytes()); 
    os.flush(); 
    os.close(); 
} 

protected void connectIfDisconected() throws JSchException { 
    if (!session.isConnected()) { 
     LOGGER.info(LogEvent.create(".connectIfDisconected()", "Reconnecting session and channel...")); 
     session.connect(); 
     if (channel != null) { 
      channel.exit(); 
     } 
     channel = (ChannelSftp) session.openChannel("sftp"); 
    } else if (!channel.isConnected()) { 
     LOGGER.info(LogEvent.create(".connectIfDisconected()", "Reconnecting channel...")); 
     channel.connect(); 
    } 
} 

세션 구성입니다 : 여기

코드입니다! 내가 터미널 모두를 사용하여 동일한 시도하고 언제
com.three60t.tex.app.exceptions.business.BusinessException: Error while delivering to Client communicator : Permission denied 
     at com.three60t.integration.posttrade.utils.DefaultReporter.reportError(DefaultReporter.java:68) 
     at com.three60t.integration.posttrade.transformationService.InternalTransformationService.reportError(InternalTransformationService.java:439) 
     at com.three60t.integration.posttrade.transformationService.InternalTransformationService.deliver(InternalTransformationService.java:378) 
     at com.three60t.integration.posttrade.transformationService.InternalTransformationService.doDeliver(InternalTransformationService.java:314) 
     at com.three60t.integration.posttrade.transformationService.InternalTransformationService.transform(InternalTransformationService.java:305) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:497) 
     at com.three60t.tex.communication.message.handler.MessageDispatcher.dispatchToObject(MessageDispatcher.java:722) 
     at com.three60t.tex.communication.message.handler.MessageDispatcher.doExecuteObject(MessageDispatcher.java:543) 
     at com.three60t.tex.communication.message.handler.MessageDispatcher.access$200(MessageDispatcher.java:77) 
     at com.three60t.tex.communication.message.handler.MessageDispatcher$1.run(MessageDispatcher.java:264) 
     at com.three60t.tex.communication.message.handler.MessageDispatcher$3.run(MessageDispatcher.java:444) 
     at com.three60t.concurrent.executor.v2.RunnableWithTimings.run(RunnableWithTimings.java:81) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: 3: Permission denied 
     at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) 
     at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:753) 
     at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:700) 
     at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:694) 
     at com.three60t.integration.tradeimporters.sftp.DtccSftpClient.uploadFile(DtccSftpClient.java:34) 
     at com.three60t.integration.tradeimporters.sftp.SFTPTransportDtcc.upload(SFTPTransportDtcc.java:41) 
     at com.three60t.framework.communication.integration.SFTPTransport.upload(SFTPTransport.java:148) 
     at com.three60t.integration.tradeimporters.sftp.SFTPTransportDtcc.upload(SFTPTransportDtcc.java:25) 
     at com.three60t.integration.tradeimporters.sftp.SFTPTransportDtcc.deliver(SFTPTransportDtcc.java:55) 
     at com.three60t.integration.posttrade.transformationService.InternalTransformationService.deliver(InternalTransformationService.java:362) 
     ... 15 more 

라인

OutputStream os = channel.put(targetFile); 
에 다음과 같은 예외를 받고 있어요 파일을 넣어 시도하고 있지만

잘 작동합니다!

sftp [email protected] 
Connecting to fdmoverspse.dtcc.com... 
[email protected]'s password: 
sftp> put myfile.xml //!DTS4.UP.G5TB4.S60301 
Uploading myfile.xml to //!DTS4.UP.G5TB4.S60301 
myfile.xml  100% 7901  7.7KB/s 00:00 
sftp> 

수정 방법은 무엇입니까?

+0

"어떻게 터미널을 사용하여 동일하게"하고 있습니까? 우리에게 보여줘! –

+1

연결하려는 LPAR에 대한 z/OS syslog에 보안 관련 메시지가 있습니까? – cschneid

+0

그리고 ChannelSftp에는 무엇이 있습니까? "잘 연결되었습니다!"라는 말의 근거는 무엇입니까? –

답변

1

ChannelSftp.glob_remote에는 경로가 두 개의 슬래시로 시작하는 경우 두 번째 슬래시를 제거하는 "버그"가 있습니다. 대신이의

:

if(!pattern_has_wildcard){ 
    if(!dir.equals("/")) 
    dir+="/"; 
    v.addElement(dir+Util.unquote(_pattern)); 
    return v; 
} 

코드는 같은되어야한다 :

if(!pattern_has_wildcard){ 
    if(foo != 0) 
    dir+="/"; 
    v.addElement(dir+Util.unquote(_pattern)); 
    return v; 
} 
+0

놀라운! 고맙습니다! 그 버그를보고하려고합니다! –

+0

버그를 신고하면 여기에 링크를 게시하십시오. –

+1

버그가 제기 됨 https://sourceforge.net/p/jsch/bugs/102/ –

1

나는 sshj를 사용하여 파일을 넣을 수 있었다. 나를 위해 일하는 간단한 클라이언트가 있습니다.

public class DtccSftpSshjClient { 

private static final Logger LOGGER = Log.getLogger(DtccSftpSshjClient.class); 
private String hostname; 
private String username; 
private String password; 

private SSHClient client; 


public DtccSftpSshjClient(String hostname, String username, String password) throws IOException { 
    this.hostname = hostname; 
    this.username = username; 
    this.password = password; 
    client = new SSHClient(); 
    client.addHostKeyVerifier(new PromiscuousVerifier()); 
    client.connect(hostname); 
    client.authPassword(username, password); 
} 

public void upload(String refId, String message, String dest) { 
    try { 
     LocalSourceFile messageFile = new InMemoryTradeFile(message, refId); 
     SFTPClient sftp = client.newSFTPClient(); 
     sftp.put(messageFile, dest); 
     sftp.close(); 
    } catch (Exception e) { 
     LOGGER.error(e.toString()); 
    } 

} 

public void closeConnection() throws IOException { 
    client.disconnect(); 
} 

private class InMemoryTradeFile extends InMemorySourceFile { 

    String message; 
    String refId; 

    public InMemoryTradeFile(String message, String refId) { 
     this.message = message; 
     this.refId = refId; 
    } 

    @Override 
    public String getName() { 
     return refId; 
    } 

    @Override 
    public long getLength() { 
     return message.getBytes().length; 
    } 

    @Override 
    public InputStream getInputStream() throws IOException { 
     return new ByteArrayInputStream(message.getBytes()); 
    } 
} 
} 

희망이 있습니다.

관련 문제