Quantcast
Channel: Rebex Q&A Forum - Recent questions and answers
Viewing all 3884 articles
Browse latest View live

How can you react to an abort transfer command on the FileServer?

$
0
0

I am using the Rebex FileServer and a Rebex SFTP client. The server application is linked to a database to store users and custom file details.
The FileUploaded/FileDownloaded event is used to update the database and rename the file uploaded.
The problem I have is that if the client hits the Abort Transfer button, the server aborts the upload but still fires the FileUploaded/FileDownloaded event so the database becomes inaccurate.
Is there an event or some way to recognize on the server that the transfer has been aborted so I can alter my custom FileUploaded/FileDownloaded event handling?

I am using the PutFileAsync command for uploading and the Download command for downloading.


Answered: Does the file server disconnect or force authentication of users after a specified period of inactivity?

$
0
0

MaxSessionDuration specifies when SSH session renegotiation is to occur. This does not disconnect the user, it just renegotiates encryption keys. Forcing reauthentication is not supported by the SSH protocol.

Disconnect users after a period of inactivity is not currently supported, although some form of it can be implemented by closing instances of ServerSession obtained through FileServer.Sessions, although detecting inactivity might be tricky.

How to force a SFTP.Connect to abort.

$
0
0

In one thread I have this:
_client = New Sftp
_client.Connect(ipaddress, ipport) ' timeout on connect is 6 seconds

In another thread
_client.Dispose()

I can see that Dispose() will finish while Connect is still timing out.

Is there a way to force Connect to Abort immediately and be done by the time Dispose returns?

If no way to abort THEN is there something I can wait on to make sure Connect has returned?

Would ConnectAsync help? and if so how?

Thanks
Tom

How to retrieve file from a foreach statement but using memory stream instead of path(C:\\)

$
0
0

My objective is to take each file that is in SftpItem item and deserialize the item and place in sql database. My problem arises when trying to retrieve the item out of the for each loop.

private void GetListFinished(Task t) {

        //show error
        if (t.IsFaulted)
        {
            Console.WriteLine("An error occurred: {0}", t.Exception.ToString());

            return;
        }
         // show cancel notification
         if (t.IsCanceled)
        {
            Console.WriteLine("Cancel");
            return;
        }


        SftpItemCollection list = t.Result;

        foreach (SftpItem item in list)
        {
            Console.WriteLine(item);
            Console.Write(item.Length);


            //open a file in memory

            MemoryStream inMemoryCopy = new MemoryStream();
            using (FileStream msFile = 
          File.OpenRead(item.path))   
            {
                msFile.CopyTo(inMemoryCopy);
            }

Terminal IScreen best approach

$
0
0

We are trying to implement our own display of the terminal screen using the IScreen interface and this is the skeleton of the code:

class RebexScreen : IScreen
{
   RebexClient m_TnClient;
   public RebexScreen (RebexClient cc)
   {
      m_TnClient = cc;
   }
   public void Clear(int left, int top, int width, int height)
   {
      // clear screen data
   }
   public void Copy(int sourceLeft, int sourceTop, int targetLeft, int targetTop, int width, int height)
   {
      // copy screen data
   }
   public void Resize(int width, int height)
   {
   }
   public void Scroll(int rows)
   {
     // move screen data up
   }
   public void SetColor(int foreground, int background)
   {
   }
   public void SetCursorPosition(int x, int y, bool visible)
   {
      if (visible)
      {
         // update cursor pos
      }
   }
   public void Write(int left, int top, string text)
   {
      TerminalCell cell = m_TnClient.m_rxScript.Terminal.Screen.GetCell(left, top);
      // my drawing code:
   }
}

class RebexClient 
{
   public async Task<bool> ConnectAsync(ConnectionSettings cs)
   {
      m_rxTelnet = new Telnet(cs.HostNameIP, cs.Port, cs.SupportSSL ? SslMode.Explicit : SslMode.None);
      m_rxTelnet.Timeout = cs.TimeOutSec * 1000;
      TerminalOptions options = new TerminalOptions() {
         TerminalType = TerminalType.Ansi,
         Columns = cs.CustomCols,
         Rows = cs.CustomRows,
      };
      options.ColorScheme = Rebex.TerminalEmulation.ColorScheme.Custom;
      options.SetColorIndex(SchemeColorName.Foreground, 2);
      options.SetColorIndex(SchemeColorName.Background, 6);
      try
      {
         m_rxScript = null;
         m_rxScript = await m_rxTelnet.StartScriptingAsync(options).ConfigureAwait(false);
         RebexScreen my = new RebexScreen(this);
         TerminalExtensions.SetCustomScreen(m_rxScript.Terminal, my);
         m_rxScript.Terminal.Disconnected += Terminal_Disconnected;
         m_rxScript.Terminal.DataReceived += Terminal_DataReceived;
      }
      catch (NetworkSessionException ex)
      {
         switch (ex.Status)
         {
            case NetworkSessionExceptionStatus.UnclassifiableError:
               break;
            case NetworkSessionExceptionStatus.OperationFailure:
               break;
            case NetworkSessionExceptionStatus.ConnectFailure:
               break;
            case NetworkSessionExceptionStatus.ConnectionClosed:
               break;
            case NetworkSessionExceptionStatus.SocketError:
               break;
            case NetworkSessionExceptionStatus.NameResolutionFailure:
               break;
            case NetworkSessionExceptionStatus.ProtocolError:
               break;
            case NetworkSessionExceptionStatus.OperationAborted:
               break;
            case NetworkSessionExceptionStatus.ServerProtocolViolation:
               break;
            case NetworkSessionExceptionStatus.Timeout:
               break;
            case NetworkSessionExceptionStatus.AsyncError:
               break;
            default:
               break;
         }
         ReportError(ex.Message);
      }
      catch (Exception e)
      {
         ReportError(e.Message);
      }
      Task.Run(() =>
      {
         try
         {
            while (m_rxScript.Process(int.MaxValue) != TerminalState.Disconnected) ;
         }
         catch {}
      }).Forget();
      return true;
   }
   private void Terminal_DataReceived(object sender, DataReceivedEventArgs e)
   {
   }
   private void Terminal_Disconnected(object sender, EventArgs e)
   {
   }
   public async Task DisconnectAsync()
   {
      await Task.Run(() =>
      {
         try
         {
            m_rxScript.Terminal.Dispose();
            m_rxScript.Close();
         }
         catch {}
      }).ConfigureAwait(false);
   }
   public async Task<bool> SendAsync(byte[] acData, int nOffset, int nLen)
   {
      await Task.Run(() => m_rxScript.SendData(acData, nOffset, nLen)).ConfigureAwait(false);
      return true;
   }
}

1) I am assuming the IScreen.Write is the place to implement the drawing of text to my screen and the way to get the color and underline attributes is by calling the GetCell method there. Is that correct?

2) Setting the default foreground and background using SetColorIndex does not seem to work. I tried it with the Terminal Control and it works there but not here with the VirtualTerminal. Am I missing something?

3) Should I be using the Terminal_DataReceived event? But with that, there is no information about position of text.

4) Are there attributes for reverse video, double width/double height? If not, any plans of providing that in the near future?

5) Any way to disable 8-bit control characters?

Thank you.

Answered: FTP State "reset"

$
0
0

Hello, have you tried calling Ftp object's Disconnect() method?

Answered: How to force a SFTP.Connect to abort.

$
0
0

This behavior is caused by the fact, that the Dispose method is not called on the currently connecting socket.

We classified this as a bug. It will be fixed in next public release.

Facing issues using PutFIleasync

$
0
0

Hi,
I am trying to upload a file usinf memory stream.
I amd calling below function and passing memory stream and filename.
Bleow code executes OK without any exception, but file is not created.Am I missing something.

Dim asyncResult = ssh.PutFileAsync(ms, Filename)

asyncResult.Wait()

Answered: Older FTP library together with recent SFTP library in same app?

$
0
0

Hi,

you can either buy (new) Rebex SFTP and use its older version, or you need to update your old FTP/SSL by renewing its support contract (recommended).
You can also upgrade your old FTP/SSL to Rebex File Transfer Pack which contains both FTP/SSL and SFTP (plus File Server), so you will always have the same version of both products.
Please contact us on: sales@rebex.net to receive an upgrade offer.

Rebex.Net.SshException: The operation was not completed within the specified time limit

$
0
0

Hello

While doing sftp.GetFile with a 500Mb file, i get the exception:

2018-07-31 15:13:14.502 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9045, 28672 bytes)
2018-07-31 15:13:14.502 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9061, 0x0, 259682304, 28672)
2018-07-31 15:13:14.524 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9046, 28672 bytes)
2018-07-31 15:13:14.524 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9062, 0x0, 259710976, 28672)
2018-07-31 15:13:14.542 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9047, 28672 bytes)
2018-07-31 15:13:14.542 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9063, 0x0, 259739648, 28672)
2018-07-31 15:13:14.561 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9048, 28672 bytes)
2018-07-31 15:13:14.561 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9064, 0x0, 259768320, 28672)
2018-07-31 15:13:14.577 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9049, 28672 bytes)
2018-07-31 15:13:14.577 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9065, 0x0, 259796992, 28672)
2018-07-31 15:13:14.599 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9050, 28672 bytes)
2018-07-31 15:13:14.603 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9066, 0x0, 259825664, 28672)
2018-07-31 15:13:14.615 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9051, 28672 bytes)
2018-07-31 15:13:14.615 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9067, 0x0, 259854336, 28672)
2018-07-31 15:13:14.633 DEBUG Sftp(9)[1] Response: SSHFXPDATA (9052, 28672 bytes)
2018-07-31 15:13:14.633 DEBUG Sftp(9)[1] Command: SSHFXPREAD (9068, 0x0, 259883008, 28672)
2018-07-31 15:15:14.656 ERROR Sftp(9)[1] SSH: Rebex.Net.SshException: The operation was not completed within the specified time limit.
in Rebex.Net.SshSession.wwqq[a,b](vgmq2 adk, Int32 adl, vgmr adm, b adn, a ado, a adp) in Rebex.Net.SshSession.wwqp[a,b](vgmq2 adi, b adj)
in Rebex.Net.SshChannel.rphn[a,b](vgmq2 va, b vb) in Rebex.Net.SshChannel.Receive(Byte[] buffer, Int32 offset, Int32 count) 2018-07-31 15:15:14.657 DEBUG Sftp(9)[1] Info: Waiting for 15 outstanding read requests to arrive. 2018-07-31 15:17:14.672 ERROR Sftp(9)[1] SSH: Rebex.Net.SshException: The operation was not completed within the specified time limit. in Rebex.Net.SshSession.wwqq[a,b](vgmq2 adk, Int32 adl, vgmr adm, b adn, a ado, a adp)
in Rebex.Net.SshSession.wwqp[a,b](vgmq2 adi, b adj) in Rebex.Net.SshChannel.rphn[a,b](vgmq2 va, b vb)
in Rebex.Net.SshChannel.Receive(Byte[] buffer, Int32 offset, Int32 count)
2018-07-31 15:17:14.673 ERROR Sftp(9)[1] Info: Rebex.Net.SshException: The operation was not completed within the specified time limit.
in Rebex.Net.SshSession.wwqq[a,b](vgmq2 adk, Int32 adl, vgmr adm, b adn, a ado, a adp) in Rebex.Net.SshSession.wwqp[a,b](vgmq2 adi, b adj)
in Rebex.Net.SshChannel.rphn[a,b](vgmq`2 va, b vb)
in Rebex.Net.SshChannel.Receive(Byte[] buffer, Int32 offset, Int32 count)
in ctci.licr(Byte[] m, Int32 n, Int32 o)
in ctcy.mpez(Int32 arz)
in ctcy.mpfb(hffs& asc)
in ctcy.mpey(UInt32 arx, Boolean ary)
in ctcy.mpea(UInt32 apa, ctch apb)
in Rebex.Net.Sftp.ypkq(ctch sv, String sw, Stream sx, Int64 sy, Int64 sz, hetr ta)

Thanks, Marcelo.

Possibility to catch the beggining of file transfer.

$
0
0

Hello, is there a possibility in rebex sftp server of catching the beginning of file transfer?

Thanks.

Answered: Rebex.Net.SshException: The operation was not completed within the specified time limit

$
0
0

From the log, it seems that the server didn't send any data for 60 seconds so the client timed out. See highlighted part of the log:

2018-07-31 15:13:14.633 DEBUG Sftp(9)1 Command: SSHFXPREAD (9068, 0x0, 259883008, 28672)
2018-07-31 15:15:14.656 ERROR Sftp(9)1 SSH:
Rebex.Net.SshException: The operation was not completed within the
specified time limit.

It can be caused by two cases:

  1. The client failed to receive the packet.
  2. The server failed to send the packet.

To determine which case arose, you have to use a network analyzer (such as WireShark) and monitor the traffic.


However, I noticed following message in the log:

Info: Waiting for 15 outstanding read requests to arrive.

By default, transfer requests are queued to improve transfer speed. Please, try to disable this feature like this:

var client = new Sftp();
client.Settings.DisableTransferQueue = true;

Or decrease the queue length like this (default is 16):

client.Settings.DownloadQueueLength = 2;

Disabling transfer queue can solve the issue, but it can have negative effect to transfer speed. Unfortunately, some servers are not able to handle queued request, so this is the only option in that case.

Rebex.Net.FtpBatchTransferException: Cannot upload file

$
0
0

I am getting an error message indicating that RebEx can not access the file. Is there anything I can try for troubleshooting this error?

FTP error: CannotTransferFile.
Recommended action:
ThrowException. Rebex.Net.FtpBatchTransferException:
Cannot upload file ('fileName.txt').
can't access file (550). --->
Rebex.Net.FtpException: Cannot upload file ('fileName.txt').
can't access file (550). --->
Rebex.Net.FtpException: can't access file (550).
at Rebex.Net.Ftp.UM(KOW D, FtpResponse N, String T, Int64 O, String J, Boolean L, Boolean A)
at Rebex.Net.ROW.ZW()
at Rebex.Net.KOW.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at Rebex.LT.Dispose(Boolean disposing)
at Rebex.LT.VJ()
at Rebex.Net.Ftp.OY(String D, String N, Stream T, Int64 O, Int64 J, WU L)
at Rebex.Net.Ftp.OY(String D, String N, String T, Int64 O, Int64 J, Int64 L, WU A)
at Rebex.Net.YXW.GT(SH D, SH N, String T, String O, Int64 J, Int64 L) --- End of inner exception stack trace --- --- End of inner exception stack trace ---

Possibility to catch the beggining of file transfer.

$
0
0

Hello, is there a possibility in rebex sftp server of catching the beginning of file transfer?

Thanks.

Answered: Error codes for certificate issues?

$
0
0

Hello,

i) When the trust between the client and server cannot be established via TLS (HTTPS is HTTP over TLS), a TlsException is thrown and will appear in the exception chain cought by your application. To find the TlsException, pass the caught exception to a routine such as this one:

    private TlsException GetTlsException(Exception error)
    {
        while (error != null)
        {
            var tlsError = error as TlsException;
            if (tlsError != null)
            {
                return tlsError;
            }

            error = error.InnerException;
        }

        return null;
    }

However, we have to point out that it is strongly discouraged to fall back to HTTP mode when HTTP over TLS does not work. Doing so would make it trivial for an attacker to force your connections into unencrypted mode simply by disrupting the TLS traffic.

ii), iii), v) Once you find the TlsException using the approach described above, inspect its ProtocolMessage property. It will contain one of the following values:
CloseNotify
UnexpectedMessage
BadRecordMac
DecryptionFailed
RecordOverflow
DecompressionFailure
HandshakeFailure
NoCertificate
BadCertificate
UnsupportedCertificate
CertificateRevoked
CertificateExpired
CertificateUnknown
IllegalParameter
UnknownCa
AccessDenied
DecodeError
DecryptError
ExportRestriction
ProtocolVersion
InsufficientSecurity
InternalError
UserCanceled
NoRenegotiation
UnknownError

These correspond to TLS error alerts and include certificate errors you are interested in.

iv) When the client certificate returned by a certificate request handler doesn't is not associated with a private key, a TlsException with ProtocolMessage of "InternalError" and a Message of "Certificate does not have a private key." will be thrown. It's recommended to prevent this from occurring by making sure that the certificate retured by a custom certificate request handler has a private key - use Certificate's HasPrivateKey method to make sure.


Cannot enable private Key based authentication.

$
0
0

I have public and private key files.It was generated by Rebex library and cannot load the file in RebexTinySftpServer.exe(XML config file).

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "Saved by Rebex SSH"
AAAAB3NzaC1yc2EAAAADAQABAAAAgQDTztzXfIePFw6zAOh0mGmozmh6G3cv9LYC
rEF2Ad5PLKMJegPlrd5KxRx7fDvnQEkPC8MaHhX3k2074nW3Cxzv9NTB13bZ3tGi
E4yChxynIG6C0qYHgQ/b9QnfJ+rfdFbVX/hMlGbhBO6mvwqHkkVL1crrpY7T80pv
i4QJ7TITWQ==
---- END SSH2 PUBLIC KEY ----
(The pubic Key file is in .pub extension)

-----BEGIN ENCRYPTED PRIVATE KEY-----
MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQI52Iz7KJj1kQCAggA
MBQGCCqGSIb3DQMHBAi1W+6h0EuxwwSCAoBJmfg2aG0IuEJPC3mlZ2Cbtiin3ajh
9aN4KpEG+x2IkW9WPLsNg9Jjrsd+tW+5ULAvmZQBtB3t8pn2fpeDnrdhTjD8ZQbP
oCVwuNYhG7sknuUk+QwOZED93+L0EbDLApWymGMnG7XObeh08GQQDiRrWI9lfutp
IUslBjFSCAZCVOxswV2XWtJpWFyYp0Y+F6MXJh/zp3fd6+KVhf6B6KoXimr0dJvh
dFxEktLhl3pp6lxwdt0WFEMbC/zUreqyKOxpkHz9GGm+BrkosqW/hpfqCPy4gJpB
r50cHbC6kRecR+g6evMTA+fc7FNAWvxeABdHNrb8FPSwUy9okaw6xMwAQzWpjP4Y
lADsE5R374hPPmfJB4QmtaIlfz4vYXq2MJugfDUlD++SRqXoNDsRWfJYb1MsfZhl
AEBOv7sr/0OTDuAbk506ju7bc7Otci+Z9AbjzXmaVeAei9glOv+v5tzl0pr2OeKI
qT1HSJKQh8WTaQp58nsdM0Aq52IcZUQuveGjbhNk77nqypyijgtBnlEQBXwwcTwm
JQ/mRkHFaLdXsNUsyc8ZZOtFwMNIhz2g4mjvPgcF5v7kZiQwpilwY47nyBTta0zQ
7YjpnO0p44mUqbeXNeZb0Bvy4TDR0nIQT9vli39nvGc/vR9OH+CGK2IZivfFIXcH
XmbSVraxn5nDu/BlnHl8ijuE/9/rvoIibueE5xWyIovuXmtdTK463j6tYjtJWyUP
i+L0GVmeFH+IlqAx7+3h6K75zlSeNJFIb8I/Vkyi/qsINh5MOwjGjSsvI/hoMAcs
/rbWmGqZ/r01qRwlro90z860/V5vm0+CvCvAPUwV1tmWLX3+g7veEmv0
-----END ENCRYPTED PRIVATE KEY-----

Whenever I tried to load the public key like this
<add key="userPublicKeyDir" value="generated_key.pub"/> the tiny server didn't start.How can I fix this issue?There's no error log.Code to connect from client

Possibility to catch the beggining of file transfer.

$
0
0

Hello, is there a possibility in rebex sftp server of catching the beginning of file transfer?

Thanks.

Answered: Cannot enable private Key based authentication.

$
0
0

The userPublicKeyDir key is supposed to be a directory path, not a file path. This makes it possible to use multiple public keys. Please create a new directory, copy generated_key.pub into it and specify the directory path (can be relative to RebexTinySftpServer.exe's directory) in userPublicKeyDir key's value.

For example:

<add key="userPublicKeyDir" value="C:\MyServer\PublicKeys" />

Or:

<add key="userPublicKeyDir" value="keys" />

This said, you have actually discovered a bug. The server should still start if the key value is a file path and report an error. We will fix this. Thanks for reporting the issue.

How to open FileNode in stream for further transition?

$
0
0

Hello, I'm trying to receive the file in custom realisation of FileSystem and move it without saving on remote server. For that, I need to get the stream of file, how can I do that in such method?

Thanks.

    /// <inheritdoc />
    protected override FileNode CreateFile(DirectoryNode parent, FileNode child)
    {
        //// second throw;
        FileStream file = File.Open(child.Path.StringPath, FileMode.Open);
        throw new NotImplementedException();
    }

Answered: Secure IMAP issue

$
0
0

The "Server certificate was rejected because of an unknown certificate authority" indicates that the certificate validation failed because the root certificate authority is not trusted by the Windows account under which the application runs. The recommended solution is to add the server root certification authority certificate into a list of trusted root CAs.

Check out the following blog posts for additional information:
- http://blog.rebex.net/howto-server-certificate-rejected-exception/
- http://blog.rebex.net/introduction-to-public-key-certificates/

Another alternative would be to implement a custom verifier (possibly based on the ImapBrowse one) that replaces certificateChain.Validate call with this:

ValidationResult res = certificateChain.Validate(commonName, ValidationOptions.AllowUnknownCa);

This makes it succeed despite an untrusted root CA. However, in addition to this, you would have to make sure that raw certificate data returned by certificateChain.RootCertificate.GetRawCertData() is actually identical to the proper root certificate. Otherwise, an attacker with access to any device along the way between the client and the server would be able to trick the application into connecting to his own server.

The "An exception occurred in certificate verifier" indicates that an exception occurred inside the custom verifier routine. To determine the cause of that, put the contents of that routine into try/catch block and see which exception gets caught.

Viewing all 3884 articles
Browse latest View live