Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCP user friendly exceptions #401

Open
fioan89 opened this issue Aug 1, 2023 · 4 comments
Open

SCP user friendly exceptions #401

fioan89 opened this issue Aug 1, 2023 · 4 comments

Comments

@fioan89
Copy link

fioan89 commented Aug 1, 2023

Version

2.10.0

Bug description

When using the SCP client to upload a file to a remote location that does not exist a WindowClosedException is raised instead of a more user friendly SCP exception detailing the reason of why the upload/download failed.

The snippet of code below raises a WindowClosedException exception when /remote/path/that/does/not/exist doesn't exist.

val session = sshClient.connect(
    username,
    hostname,
    port
).verify(5000).session
session.auth().await(5000)

scpClient = ScpClientCreator.instance().createScpClient(session)
scpClient.upload("/local/path/file_name",  "/remote/path/that/does/not/exist/file_name", options)

Actual behavior

e = {WindowClosedException@37364} "org.apache.sshd.common.channel.WindowClosedException: Already closed: RemoteWindow[client](ChannelExec[id=0, recipient=0]-ClientSessionImpl[ifaur@localhost/127.0.0.1:2222])"
 disconnectCode = 0
 backtrace = {Object[6]@37368} 
 detailMessage = "Already closed: RemoteWindow[client](ChannelExec[id=0, recipient=0]-ClientSessionImpl[ifaur@localhost/127.0.0.1:2222])"
 cause = {WindowClosedException@37364} "org.apache.sshd.common.channel.WindowClosedException: Already closed: RemoteWindow[client](ChannelExec[id=0, recipient=0]-ClientSessionImpl[ifaur@localhost/127.0.0.1:2222])"
 stackTrace = {StackTraceElement[39]@37373} 
  0 = {StackTraceElement@41979} "org.apache.sshd.common.channel.RemoteWindow.waitForCondition(RemoteWindow.java:230)"
  1 = {StackTraceElement@41980} "org.apache.sshd.common.channel.RemoteWindow.waitForSpace(RemoteWindow.java:187)"
  2 = {StackTraceElement@41981} "org.apache.sshd.common.channel.ChannelOutputStream.flush(ChannelOutputStream.java:278)"
  3 = {StackTraceElement@41982} "org.apache.sshd.scp.common.helpers.ScpIoUtils.writeLine(ScpIoUtils.java:82)"
  4 = {StackTraceElement@41983} "org.apache.sshd.scp.common.helpers.ScpIoUtils.sendAcknowledgedCommand(ScpIoUtils.java:94)"
  5 = {StackTraceElement@41984} "org.apache.sshd.scp.common.ScpHelper.sendAcknowledgedCommand(ScpHelper.java:724)"
  6 = {StackTraceElement@41985} "org.apache.sshd.scp.common.ScpHelper.sendDir(ScpHelper.java:686)"
  7 = {StackTraceElement@41986} "org.apache.sshd.scp.common.ScpHelper.send(ScpHelper.java:484)"
  8 = {StackTraceElement@41987} "org.apache.sshd.scp.common.ScpHelper.send(ScpHelper.java:454)"
  9 = {StackTraceElement@41988} "org.apache.sshd.scp.client.AbstractScpClient.lambda$upload$0(AbstractScpClient.java:143)"
  10 = {StackTraceElement@41989} "org.apache.sshd.scp.client.DefaultScpClient.runUpload(DefaultScpClient.java:149)"
  11 = {StackTraceElement@41990} "org.apache.sshd.scp.client.AbstractScpClient.upload(AbstractScpClient.java:143)"
  12 = {StackTraceElement@41991} "org.apache.sshd.scp.client.ScpClient.upload(ScpClient.java:106)"

Expected behavior

a SCPException or even a basic IOException with a more relevant message:

  • destination "/remote/path/that/does/not/exist/file_name" does not exist or could not be created
  • "/remote/path/that/does/not/exist/file_name" no such file or directory

Relevant log output

No response

Other information

No response

@lgoldstein
Copy link
Contributor

Actually, this is does not seem to a MINA SSHD issue but rather a specific server issue - see especially PR#428 where a missing remote file is actuall signalled as a WARNING by the OpenSSH server rather than an ERROR. Furthermore, the SCP protocol does not really provide a good mechansim for specific errors - at most, some text after the ERROR stats - which most clients (jncluding us) ignore.

@fioan89
Copy link
Author

fioan89 commented Nov 10, 2023

If remember correctly when I played with this, I also tested the SCP client shipped with Windows MinGW. That was working better with more specific/user friendly erros. I can try to reproduce the issue again and post the logs from that client.

@fioan89
Copy link
Author

fioan89 commented Nov 10, 2023

Here is an example of an error from a different scp client:

$ scp log.txt ifaur@192.168.0.68:/home/ifaur/some_remote_path/
ifaur@192.168.0.68's password:
scp: dest open "/home/ifaur/some_remote_path/": Failure
scp: failed to upload file log.txt to /home/ifaur/some_remote_path/

Something more verbose:

$ scp -v log.txt ifaur@192.168.0.68:/home/ifaur/some_remote_path/
Executing: program /usr/bin/ssh host 192.168.0.68, user ifaur, command sftp
OpenSSH_9.4p1, OpenSSL 3.1.2 1 Aug 2023
debug1: Reading configuration data /c/Users/Fauri/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.0.68 [192.168.0.68] port 22.
debug1: Connection established.
........................................................................................................................
scp: debug1: stat remote: No such file or directory
scp: dest open "/home/ifaur/some_remote_path/": Failure
scp: failed to upload file log.txt to /home/ifaur/some_remote_path/
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3776, received 3920 bytes, in 0.4 seconds
Bytes per second: sent 9221.3, received 9572.9
debug1: Exit status 0

I've removed the key handshake bits for brevity.

@lgoldstein
Copy link
Contributor

This log does not reveal what is being transmitted at the low-level SCP protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants