SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

An error occurred, but no specific error code exists to describe the failure

Open eLPe21 opened this issue 2 months ago • 4 comments

Hi,

I'm getting the below error on various version ( including 2025.1.0 )

Unhandled exception occurred Renci.SshNet.Common.SshException: Failed to upload /2880389.xml to ./2880389.xml ---> Renci.SshNet.Common.SftpException: An error occurred, but no specific error code exists to describe the failure. at Renci.SshNet.Sftp.SftpSession.RequestClose(Byte[] handle) at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback, Boolean isAsync, CancellationToken cancellationToken) at Renci.SshNet.SftpClient.InternalSynchronizeDirectories(String sourcePath, String destinationPath, String searchPattern, SftpSynchronizeDirectoriesAsyncResult asyncResult) --- End of inner exception stack trace ---

I'm properly connected to the SFTP server:

Files in remote directory ./username: ["processing"] Current working directory: /

And I'm able to successfully upload a file using lftp:

lftp -u username sftp://some_server.com -e "put /tmp/test.xml -o /test5.xml; bye"

I don't have problems downloading files from this server.

Telnet to the server reoprts:

SSH-2.0-DataPowerSSH_1.1

I've been trying both:

SftpClient.Upload and SftpClient.SynchronizeDirectories(sourcePath, ".", "*.xml")

Any idea what might be causing the problem? Tried to specify the remote path as / , ./ and ./username

Thanks

edi1 Maybe debug logs will be useful and also the fact, the server only supports: ssh-rsa

info: Renci.SshNet.Connection.DirectConnector[0] Initiating connection to 'Unspecified/some_server.com:22'. info: Renci.SshNet.Session[0] Server version 'SSH-2.0-DataPowerSSH_1.1'. dbug: Renci.SshNet.Session[0] [(null)] Performing curve25519-sha256 key exchange. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Creating aes128-ctr server cipher. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Creating aes128-ctr client cipher. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Creating hmac-sha2-256 server hmac algorithm. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Creating hmac-sha2-256 client hmac algorithm. dbug: Renci.SshNet.SftpClient[0] Disposing client. info: Renci.SshNet.SftpClient[0] Disconnecting client. dbug: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Disposing session. info: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Disconnecting session. dbug: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Shutting down socket. dbug: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Disposing socket. dbug: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Disposed socket. info: Renci.SshNet.Session[0] [5ACDE0EBBF5E5D1ACBF0B8452F18745B0D6126EFB878BD01C445FCD9FD937224] Raised exception Renci.SshNet.Common.SshConnectionException: Software caused connection abort ---> System.Net.Sockets.SocketException (53): Software caused connection abort at Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan readTimeout) at Renci.SshNet.Session.TrySocketRead(Socket socket, Byte[] buffer, Int32 offset, Int32 length) at Renci.SshNet.Session.ReceiveMessage(Socket socket) at Renci.SshNet.Session.MessageListener() --- End of inner exception stack trace ---

eLPe21 avatar Nov 12 '25 10:11 eLPe21

Unfortunately this generic error can mean anything depending on the implementation of the server. Sometimes it can be e.g. part of the path does not exist and the server says "Failure" rather than "NoSuchFile". It is odd though that is seems to be happening when closing the file. Does the file exist on the server after the error?

The library has quite a lot of "path canonicalisation" stuff (https://github.com/sshnet/SSH.NET/blob/e5ad82c8c654d9234c6c6fee869e5ad05fc11f3e/src/Renci.SshNet/Sftp/SftpSession.cs#L94) that is probably not present in other implementations. I had wondered if it had something to do with that but throwing out of RequestClose would make that less likely.

The logs look fine. I imagine the server logs would have more information but guessing this is not your server.

Rob-Hague avatar Nov 13 '25 19:11 Rob-Hague

Hi , thanks for reply. Progress logs even shows % upload , but the file, never shows up on the server at all. Neither during upload ( tried to list the folder during uploads ) or after it. And yeah, it's not my server so I'm limited a bit to what I've provided. WIll try to contact server-admin but being able to upload files manually using LFTP made me create this issue.

Tried to clone the sources and force to use the path provided skipping canonical path , but big chance I've done something wrong.

eLPe21 avatar Nov 13 '25 21:11 eLPe21

It might be sufficient to try this as an experiment:

diff --git i/src/Renci.SshNet/SftpClient.cs w/src/Renci.SshNet/SftpClient.cs
index 77014e9a..bcc84ece 100644
--- i/src/Renci.SshNet/SftpClient.cs
+++ w/src/Renci.SshNet/SftpClient.cs
@@ -2414,7 +2414,7 @@ private List<ISftpFile> InternalListDirectory(string path, SftpListDirectoryAsyn
             }
             else
             {
-                fullPath = _sftpSession.GetCanonicalPath(path);
+                fullPath = path;
                 handle = _sftpSession.RequestOpen(fullPath, flags);
             }

I can see that lsftp does request the current path: https://github.com/lavv17/lftp/blob/926cbf31a87aed00b7ab38298783302908c0d0e7/src/SFtp.cc#L220

and it does seem to use it in some (as yet uncertain) circumstances: https://github.com/lavv17/lftp/blob/926cbf31a87aed00b7ab38298783302908c0d0e7/src/SFtp.cc#L588 https://github.com/lavv17/lftp/blob/926cbf31a87aed00b7ab38298783302908c0d0e7/src/SFtp.cc#L555

lsftp also seems to print some relevant information at debug level 9. (SSH.NET would also print more at "Trace" but probably not enough at the SFTP level unfortunately)

Rob-Hague avatar Nov 13 '25 21:11 Rob-Hague

Maybe that will help, enable trace, also overwrite the fullPath as per your suggestion, tried to list files from the server and the file never appeared on the server.

info: Renci.SshNet.Session[0] Server version 'SSH-2.0-DataPowerSSH_1.1'. trce: Renci.SshNet.Session[0] [(null)] Sending message SSH_MSG_KEXINIT(20) to server: 'SSH_MSG_KEXINIT'. trce: Renci.SshNet.Session[0] [(null)] Received message SSH_MSG_KEXINIT(20) from server: 'SSH_MSG_KEXINIT'. dbug: Renci.SshNet.Session[0] [(null)] Performing curve25519-sha256 key exchange. trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Host key algorithm: we offer [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256,ssh-rsa trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Host key algorithm: they offer ssh-rsa,ssh-rsa trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Encryption client to server: we offer aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Encryption client to server: they offer [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Encryption server to client: we offer aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Encryption server to client: they offer [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] MAC client to server: we offer hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] MAC client to server: they offer [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] MAC server to client: we offer hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] MAC server to client: they offer [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Compression client to server: we offer none,[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Compression client to server: they offer none,[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Compression server to client: we offer none,[email protected] trce: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [(null)] Compression server to client: they offer none,[email protected] trce: Renci.SshNet.Session[0] [(null)] Sending message SSH_MSG_KEX_ECDH_INIT(30) to server: 'SSH_MSG_KEX_ECDH_INIT'. trce: Renci.SshNet.Session[0] [(null)] Received message SSH_MSG_KEX_ECDH_REPLY(31) from server: 'SSH_MSG_KEX_ECDH_REPLY'. trce: Renci.SshNet.Session[0] [(null)] Sending message SSH_MSG_NEWKEYS(21) to server: 'SSH_MSG_NEWKEYS'. trce: Renci.SshNet.Session[0] [(null)] Received message SSH_MSG_NEWKEYS(21) from server: 'SSH_MSG_NEWKEYS'. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Creating aes128-ctr server cipher. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Creating aes128-ctr client cipher. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Creating hmac-sha2-256 server hmac algorithm. dbug: Renci.SshNet.Security.KeyExchangeECCurve25519[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Creating hmac-sha2-256 client hmac algorithm. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_SERVICE_REQUEST(5) to server: 'SSH_MSG_SERVICE_REQUEST'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_SERVICE_ACCEPT(6) from server: 'SSH_MSG_SERVICE_ACCEPT'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_USERAUTH_REQUEST(50) to server: 'SSH_MSG_USERAUTH_REQUEST (none)'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_USERAUTH_FAILURE(51) from server: 'SSH_MSG_USERAUTH_FAILURE publickey,password (PartialSuccess:False)'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_USERAUTH_REQUEST(50) to server: 'SSH_MSG_USERAUTH_REQUEST (password)'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_USERAUTH_SUCCESS(52) from server: 'SSH_MSG_USERAUTH_SUCCESS'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_GLOBAL_REQUEST(80) from server: 'SSH_MSG_GLOBAL_REQUEST'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_OPEN(90) to server: 'SSH_MSG_CHANNEL_OPEN'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_OPEN_CONFIRMATION(91) from server: 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_REQUEST(98) to server: 'SSH_MSG_CHANNEL_REQUEST : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_WINDOW_ADJUST(93) from server: 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_SUCCESS(99) from server: 'SSH_MSG_CHANNEL_SUCCESS : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_WINDOW_ADJUST(93) from server: 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_DATA(94) to server: 'SSH_MSG_CHANNEL_DATA : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_DATA(94) from server: 'SSH_MSG_CHANNEL_DATA : #1'. dbug: Renci.SshNet.SftpClient[0] Disposing client. info: Renci.SshNet.SftpClient[0] Disconnecting client. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_EOF(96) to server: 'SSH_MSG_CHANNEL_EOF : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_CHANNEL_CLOSE(97) to server: 'SSH_MSG_CHANNEL_CLOSE : #0'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_REQUEST(98) from server: 'SSH_MSG_CHANNEL_REQUEST : #1'. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Received message SSH_MSG_CHANNEL_CLOSE(97) from server: 'SSH_MSG_CHANNEL_CLOSE : #1'. dbug: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Disposing session. info: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Disconnecting session. trce: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Sending message SSH_MSG_DISCONNECT(1) to server: 'SSH_MSG_DISCONNECT'. dbug: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Shutting down socket. dbug: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Disposing socket. dbug: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Disposed socket. info: Renci.SshNet.Session[0] [25C17541FF3910AFE79C8313BE65CD9859D900D679245DB00067EA4132204BCB] Raised exception Renci.SshNet.Common.SshConnectionException: Software caused connection abort ---> System.Net.Sockets.SocketException (53): Software caused connection abort at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan readTimeout) in /SSH.NET/src/Renci.SshNet/Abstractions/SocketAbstraction.cs:line 255 at Renci.SshNet.Session.TrySocketRead(Socket socket, Byte[] buffer, Int32 offset, Int32 length) in /SSH.NET/src/Renci.SshNet/Session.cs:line 1881 at Renci.SshNet.Session.ReceiveMessage(Socket socket) in /SSH.NET/src/Renci.SshNet/Session.cs:line 1246 at Renci.SshNet.Session.MessageListener() in /SSH.NET/src/Renci.SshNet/Session.cs:line 1940 --- End of inner exception stack trace ---

eLPe21 avatar Nov 14 '25 11:11 eLPe21

Sadly not 🙁 the library is lacking when it comes to logging SFTP messages. Did you have any luck with the debug output from lftp?

Rob-Hague avatar Nov 17 '25 19:11 Rob-Hague

All is ok when I use LFTP.

lftp -d -u user,pass sftp://some_server.com -e "mput 2907758.xml; bye" ---- Running connect program (ssh -a -x -s -l user some_server sftp) ---> sending a packet, length=5, type=1(INIT), id=0 <--- user@some_server's password: XXXX <--- got a packet, length=5, type=2(VERSION), id=0 ---- protocol version set to 3 ---> sending a packet, length=10, type=16(REALPATH), id=1 <--- got a packet, length=89, type=104(NAME), id=1 ---- home set to / ---- path on wire is `/2907758.xml' ---> sending a packet, length=29, type=3(OPEN), id=2 <--- got a packet, length=21, type=102(HANDLE), id=2 ---- got file handle 374634314238374135433130 (12) ---> sending a packet, length=8234, type=6(WRITE), id=3 ---> sending a packet, length=33, type=10(FSETSTAT), id=4 ---> sending a packet, length=21, type=4(CLOSE), id=5 <--- got a packet, length=17, type=101(STATUS), id=3 ---- status code=0(OK), message= <--- got a packet, length=17, type=101(STATUS), id=4 ---- status code=8(Operation not supported), message= <--- got a packet, length=17, type=101(STATUS), id=5
---- status code=0(OK), message= 8201 bytes transferred in 2 seconds (3.6K/s) ---- Disconnecting

eLPe21 avatar Nov 17 '25 19:11 eLPe21

Could you try -d9 if it does not give too much private information?

Rob-Hague avatar Nov 17 '25 19:11 Rob-Hague

Not sure if this going to be any helpful , trying to get server logs, but it's not easy ;)

lftp user@some_server:/> debug 9 lftp user@some_server:/> mput /2907533.xml ---- path on wire is `/2907533.xml' ---> sending a packet, length=29, type=3(OPEN), id=7 <--- got a packet, length=21, type=102(HANDLE), id=7 ---- got file handle 374634333442333931363130 (12) ---- eof ---> sending a packet, length=32801, type=6(WRITE), id=8 ---> sending a packet, length=11370, type=6(WRITE), id=9 ---> sending a packet, length=41, type=10(FSETSTAT), id=10 ---> sending a packet, length=21, type=4(CLOSE), id=11 <--- got a packet, length=17, type=101(STATUS), id=8
---- status code=0(OK), message= <--- got a packet, length=17, type=101(STATUS), id=9 ---- status code=0(OK), message= <--- got a packet, length=17, type=101(STATUS), id=10 ---- status code=8(Operation not supported), message= <--- got a packet, length=17, type=101(STATUS), id=11
---- status code=0(OK), message= 44105 bytes transferred lftp user@some_server:/>

eLPe21 avatar Nov 17 '25 20:11 eLPe21

@Rob-Hague almost there ;)

Managed to get some logs from the sever side. I've been told the problem is that I'm trying to upload file to USER_NAME/file_name instead of /file_name

Line 18328: 20251121T102157.050Z [0x80000001][xsltmsg][info] : tid(293587409)[request] gtid(8a7709fd69203d45117fc9d1): InternalDestination = {REDACTED}/some_user/2880389.xml Line 18329: 20251121T102157.050Z [0x80e00117][mpgw][info] : tid(293587409) gtid(8a7709fd69203d45117fc9d1): Destination URL is now {REDACTED}/some_user/2880389.xml Line 18686: 20251121T102157.392Z [0x80e00096][ftp][debug] : tid(293587409) gtid(8a7709fd69203d45117fc9d1): reply code 451 in state 'Write Data' from {REDACTED}/some_user/2880389.xml. Reply text: ' requested action aborted: local error in processing' Line 18687: 20251121T102157.392Z [0x80e0047c][ftp][notice] : tid(293587409) gtid(8a7709fd69203d45117fc9d1): file write failed for URL '{REDACTED}/some_user/2880389.xml', server response '451 requested action aborted: local error in processing Line 18697: 20251121T102157.392Z [0x81000171][mpgw][debug] Matching(Match_all): tid(293587409) gtid(8a7709fd69203d45117fc9d1): Match: Received URL [/some_user/2880389.xml] matches rule '*' Line 18715: 20251121T102157.393Z [0x80e00487][sftp][error] : tid(293587409) gtid(8a7709fd69203d45117fc9d1): SFTP Server: SSH_FXP_CLOSE [/some_user/2880389.xml] failure.

eLPe21 avatar Nov 21 '25 14:11 eLPe21

Interesting, thanks, I'll take a closer look over the weekend

Rob-Hague avatar Nov 21 '25 18:11 Rob-Hague

I'm properly connected to the SFTP server:

Current working directory: /

That is the value of sftpClient.WorkingDirectory?

I suspect the issue is coming from one of the calls to SftpSession.GetCanonicalPath. It is quite difficult to understand the logic there.

https://github.com/sshnet/SSH.NET/blob/8712c9937734944e1bb231845fd4c5881a1e35b5/src/Renci.SshNet/Sftp/SftpSession.cs#L95

e.g. if I do

client.ChangeDirectory("/");
client.SynchronizeDirectories(@"C:\tmp", ".", "*.txt");

then at some point it calls RequestRealPath with path = /./test.txt which seems a bit odd. But against OpenSSH server this returns /test.txt so it is ok.

Rob-Hague avatar Nov 23 '25 21:11 Rob-Hague

Yes it is -> Current working directory being / returned by sftpClient.WorkingDirectory

The thing they told me about the server is that ( I might be saying gibberish now ) that they use sftp for authentication etc but then the transfer is happening to some different server internally. Not sure if I understood that properly, haven't tried to do something like that myself. But I took it as upload to /username/put.xml works ok but then internally the next step is failing as /username/ is invalid path as it should be just put.xml

eLPe21 avatar Nov 23 '25 21:11 eLPe21