Would you mind raising a JIRA for that ?
This is a bug, as the the Closeeable interface specifies "If the stream is
already closed then invoking this method has no effect."

Cheers,
Guillaume

2014-09-22 4:18 GMT+02:00 George Sexton <[email protected]>:

>
> On 9/20/2014 1:43 AM, Guillaume Nodet wrote:
>
>> Can you bypass the call to close() for now and see if the file has been
>> read correctly ?
>>
>
> I have discovered the issue. StreamUtils.streamToString() instantiates an
> InputStreamReader(), and then closes it on completion. Evidently this is
> closing the underlying input stream. When I make a subsequent call to
> InputStream.close(), it throws error 2, no such file.
>
> That's kind of misleading.
>
>
>  Also, and just fwiw, the client api can be used this way:
>>
>> session.addPasswordIdentity(m_password);
>> session.auth().verify();
>> authenticated  =  true;
>>
>>
>> 2014-09-20 6:28 GMT+02:00 George Sexton <[email protected]>:
>>
>>  On 9/19/2014 5:30 PM, George Sexton wrote:
>>>
>>>  I'm having a problem using SFTP Client. I'm getting no such file. I've
>>>> tried the relative path, and the absolute path. Here's the code:
>>>>
>>>>  And just to add a little more info, I've looked at the SftpClient test
>>> code and I'm not seeing it. I started sshd in debug mode and here's what
>>> I'm seeing below. The part I don't understand is it doesn't look like the
>>> SFTP client is actually sending anything to the back end. It opens the
>>> SFTP
>>> subsystem, and then there's nothing more.
>>>
>>> debug1: sshd version OpenSSH_6.1p1
>>> debug1: read PEM private key done: type RSA
>>> debug1: private host key: #0 type 1 RSA
>>> debug1: read PEM private key done: type DSA
>>> debug1: private host key: #1 type 2 DSA
>>> debug1: read PEM private key done: type ECDSA
>>> debug1: private host key: #2 type 3 ECDSA
>>> debug1: rexec_argv[0]='/usr/sbin/sshd'
>>> debug1: rexec_argv[1]='-d'
>>> debug1: rexec_argv[2]='-p'
>>> debug1: rexec_argv[3]='1234'
>>> Set /proc/self/oom_score_adj from -1000 to -1000
>>> debug1: Bind to port 1234 on 0.0.0.0.
>>> Server listening on 0.0.0.0 port 1234.
>>> debug1: Bind to port 1234 on ::.
>>> Server listening on :: port 1234.
>>> debug1: Server will not fork when running in debugging mode.
>>> debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
>>> debug1: inetd sockets after dupping: 3, 3
>>> Connection from xx.xx.xx.xx port 60808
>>> debug1: Client protocol version 2.0; client software version
>>> SSHD-CORE-0.12.1-SNAPSHOT
>>> debug1: no match: SSHD-CORE-0.12.1-SNAPSHOT
>>> debug1: Enabling compatibility mode for protocol 2.0
>>> debug1: Local version string SSH-2.0-OpenSSH_6.1
>>> debug1: permanently_set_uid: 71/65 [preauth]
>>> debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
>>> [preauth]
>>> debug1: SSH2_MSG_KEXINIT sent [preauth]
>>> debug1: SSH2_MSG_KEXINIT received [preauth]
>>> debug1: kex: client->server aes128-ctr hmac-sha2-256 none [preauth]
>>> debug1: kex: server->client aes128-ctr hmac-sha2-256 none [preauth]
>>> debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received [preauth]
>>> debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent [preauth]
>>> debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT [preauth]
>>> debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent [preauth]
>>> debug1: SSH2_MSG_NEWKEYS sent [preauth]
>>> debug1: expecting SSH2_MSG_NEWKEYS [preauth]
>>> debug1: SSH2_MSG_NEWKEYS received [preauth]
>>> debug1: KEX done [preauth]
>>> debug1: userauth-request for user ft service ssh-connection method
>>> keyboard-interactive [preauth]
>>> debug1: attempt 0 failures 0 [preauth]
>>> debug1: PAM: initializing for "ft"
>>> debug1: PAM: setting PAM_RHOST to "c-67-166-23-167.hsd1.co.comcast.net"
>>> debug1: PAM: setting PAM_TTY to "ssh"
>>> debug1: keyboard-interactive devs  [preauth]
>>> debug1: auth2_challenge: user=ft devs= [preauth]
>>> debug1: kbdint_alloc: devices 'pam' [preauth]
>>> debug1: auth2_challenge_start: trying authentication method 'pam'
>>> [preauth]
>>> Postponed keyboard-interactive for ft from xx.xx.xx.xx port 60808 ssh2
>>> [preauth]
>>> debug1: do_pam_account: called
>>> debug1: PAM: num PAM env strings 0
>>> Postponed keyboard-interactive/pam for ft from xx.xx.xx.xx port 60808
>>> ssh2
>>> [preauth]
>>> debug1: do_pam_account: called
>>> Accepted keyboard-interactive/pam for ft from xx.xx.xx.xx port 60808 ssh2
>>> debug1: monitor_read_log: child log fd closed
>>> debug1: monitor_child_preauth: ft has been authenticated by privileged
>>> process
>>> debug1: PAM: establishing credentials
>>> User child is on pid 2673
>>> debug1: SELinux support disabled
>>> debug1: PAM: establishing credentials
>>> debug1: permanently_set_uid: 1002/65534
>>> debug1: Entering interactive session for SSH2.
>>> debug1: server_init_dispatch_20
>>> debug1: server_input_channel_open: ctype session rchan 0 win 2097152 max
>>> 32768
>>> debug1: input_session_request
>>> debug1: channel 0: new [server-session]
>>> debug1: session_new: session 0
>>> debug1: session_open: channel 0
>>> debug1: session_open: session 0: link with channel 0
>>> debug1: server_input_channel_open: confirm session
>>> debug1: server_input_channel_req: channel 0 request subsystem reply 0
>>> debug1: session_by_channel: session 0 channel 0
>>> debug1: session_input_channel_req: session 0 req subsystem
>>> subsystem request for sftp by user ft
>>> debug1: subsystem: exec() /usr/lib/ssh/sftp-server
>>> debug1: session_by_channel: session 0 channel 0
>>> debug1: session_close_by_channel: channel 0 child 2674
>>> debug1: session_close_by_channel: channel 0: has child
>>> debug1: Received SIGCHLD.
>>> debug1: session_by_pid: pid 2674
>>> debug1: session_exit_message: session 0 channel 0 pid 2674
>>> debug1: session_exit_message: release channel 0
>>> debug1: session_by_channel: session 0 channel 0
>>> debug1: session_close_by_channel: channel 0 child 0
>>> debug1: session_close: session 0 pid 0
>>> debug1: channel 0: free: server-session, nchannels 1
>>>
>>>
>>>
>>>
>>>  try  {
>>>>      ConnectFuture  connection  = VacationApplication.
>>>> getSshClient().connect(m_user,server.getHostName(),server.getPort());
>>>>      session  = (ClientSessionImpl)connection.await().getSession();
>>>>
>>>>      AuthFuture  authResult  = session.authInteractive(m_
>>>> user,m_password);
>>>>      authResult.await(10000);
>>>>      if  (!authResult.isSuccess()){
>>>>        if  (authResult.getException()==  null){
>>>>              throw  new  IOException("Error authenticating.");
>>>>      }  else  {
>>>>              throw  authResult.getException();
>>>>      }
>>>>      }
>>>>      authenticated  =  true;
>>>> }  catch  (IOException  ioe){
>>>>      VacationApplication.log("VacationUser.login(\""  +  m_user  +
>>>> "\",\"****\"), Server:"  +  server.toString(),ioe);
>>>> }  catch  (InterruptedException  ie){
>>>>      VacationApplication.log("VacationUser.login()",ie);
>>>> }  catch  (Throwable  t){
>>>>      VacationApplication.log("VacationUser.login()",t);
>>>> }
>>>>
>>>> SftpClient  ftp  =  session.createSftpClient();
>>>>
>>>> fileName="/home/"+m_user+"/"+fileName;
>>>> try  {
>>>>      InputStream  is  =  client.read(fileName);
>>>>   StreamUtils.streamToString(is);
>>>>      is.close();
>>>> }  catch  (IOException  ioe){
>>>>              // this is ok
>>>>              VacationApplication.log("Error retrieving
>>>> file:"+fileName,ioe);
>>>> }
>>>>
>>>> The error thrown is:
>>>>
>>>>
>>>> Sep 19, 2014 4:27:54 PM org.apache.catalina.core.ApplicationContext log
>>>> SEVERE: Error retrieving file: /home/ft/.forward
>>>> SFTP error (2): No such file
>>>>          at org.apache.sshd.client.sftp.DefaultSftpClient.checkStatus(
>>>> DefaultSftpClient.java:296)
>>>>          at org.apache.sshd.client.sftp.DefaultSftpClient.close(
>>>> DefaultSftpClient.java:432)
>>>>          at org.apache.sshd.client.sftp.DefaultSftpClient$4.close(
>>>> DefaultSftpClient.java:687)
>>>>          at com.mhsoftware.vacation.VacationUser.getTextFile(
>>>> VacationUser.java:144)
>>>>          at com.mhsoftware.vacation.VacationUser.getCurrentSettings(
>>>> VacationUser.java:101)
>>>>          at org.apache.jsp.EditSettings_jsp._jspService(EditSettings_
>>>> jsp.java:75)
>>>>
>>>>
>>>> On the server side, I see:
>>>>
>>>> 2014-09-19T16:27:53.806036-06:00 server sshd[25990]: Accepted
>>>> keyboard-interactive/pam for ft from xx.xxx.xxx.xxx port 47412 ssh2
>>>> 2014-09-19T16:27:53.854612-06:00 server sshd[25994]: subsystem request
>>>> for sftp by user ft
>>>>
>>>>
>>>> If anyone could point me in the write direction, I'd appreciate it.
>>>>
>>>>
>>>>
>>>>  --
>>> George Sexton
>>> *MH Software, Inc.*
>>> Voice: 303 438 9585
>>> http://www.mhsoftware.com
>>>
>>>
> --
> George Sexton
> *MH Software, Inc.*
> Voice: 303 438 9585
> http://www.mhsoftware.com
>

Reply via email to