0 votes
by (620 points)
edited by

           // Common.WriteLogService(" Downloading  SFTP file: " + FileName + " Started!","",false);
            ConnectSftp(ref dSftp);

            if (!(File.Exists(LocalPath + FileName) == true && File.ReadAllBytes(LocalPath + FileName).Length > 0))
            {
                try
                {
                    dSftp.GetFile(GetServerFilePath(FileType).ToString() + "//" + FileName, LocalPath + FileName);
                    ExtendedLogger.Log("Downloading  SFTP file: " + FileName + " Finished!", 4, "SFTP_Download");

                    //Common.WriteLogService(" Downloading  SFTP file: " + FileName + " Finished!", "", false);
                }
                catch (Exception ex)
                {
                    Common.WriteLogService(" Downloading  SFTP file: " + FileName + " Failed!", "", false);
                    Common.WriteLogService(ex.Message,ex.StackTrace,true);
                }
            }
            else
            {
                Common.WriteLogService(" SFTP file: " + FileName + " downloaded already !", "", false);
            }

            return true;
        }
        catch (Exception ex)
        {
            Common.WriteLogService(" Downloading  SFTP file: " + FileName + " Error:" + ex.Message,ex.StackTrace,true);

            if (File.ReadAllBytes(LocalPath + FileName).Length <= 0)
            {
                try
                {
                    dSftp.GetFile(GetServerFilePath(FileType).ToString() + "//OLD//" +FileName, LocalPath + FileName);

                    return true;
                }
                catch 
                {
                    //dSftp.Disconnect();commented by aswathy vm for SFTP Download issue after Server Upgrade - 17112020 
                    return false;
                }
            }
            else
            {
                //dSftp.Disconnect();commented by aswathy vm for SFTP Download issue after Server Upgrade - 17112020 
                return false;
            }                
        }
    }
    #endregion
Applies to: Rebex SFTP

1 Answer

0 votes
by (150k points)

var sftp = new Rebex.Net.Sftp();
sftp.LogWriter = new Rebex.FileLogWriter(@"C:\MyData\log.txt");
by (620 points)
when i tried to debug this code in my file nothing was written.  also can i figure out the network connection issue if any by enabling rebex log.
by (150k points)
Try this code:

    var sftp = new Rebex.Net.Sftp();
    sftp.LogWriter = new Rebex.FileLogWriter(@"C:\MyData\log.txt", LogWriter.Debug);
    sftp.Connect("test.rebex.net");

Does this write anything to the log file?
by (620 points)
now it is logging when i set the sftp object correctly.
can i track the network issue if any by enabling rebex communication logging without using any network analyzer tool
i mean the packets of data we send to server and whether we got response from server etc. I am connecting and uploading etc. using the windows service and issue happening intermittently
by (620 points)
Please respond to the below
can i track the network issue if any by enabling rebex communication log without using any network analyzer tool
by (150k points)
I think I already mostly addressed this question here: https://forum.rebex.net/22824/how-resolve-sftp-connectivity-issue-happening-using-rebex?show=22846#c22846

You can get a communication log at the SSH protocol level from Rebex SFTP if you enable logging at LogLevel.Verbose. But if the issue you are dealing with is still the same ("No connection could be made because the target machine actively refused it" error), you won't see any data packets in the log because no TCP connection has been established, and because raw network packets below TCP level are not accessible to user space applications (Wireshark installs and uses a driver to gain access to raw network traffic).
...