0 votes
by (460 points)

I had an issue of fetching bulk volume of files inward via sftp. It worked fine by fetching on the fly and also by registering and unregistering the same for each loop call.

For much more perfection, I have tried to register the event handler once without unregistering for each loop cycles . But I am unable to list files since it is unable to pass additional parameters(say Inward message types and their respective values) to the event handler SftpListItemReceivedEventHandler . Awaiting a response on this soon.

I have updated the entire core code below:

Code:
#region ListInwardCBFiles
private List ListInwardCBFiles()
{
listSftp = new Sftp();
SFTPFile objSFTPFile;
List ListSFTPFile = new List();
try
{
if (ConnectSftp(
listSftp))
{
objSFTPFile = new SFTPFile();
foreach (InwardMessageType t in Enum.GetValues(typeof(InwardMessageType)))
{

                 foreach (CBExtension r in Enum.GetValues(typeof(CBExtension)))
                 {

                     _listSftp.ListItemReceived += client_ListItemReceived;//register
                     _listSftp.GetList(GetSFTPServerPath(Enum.GetName(typeof(InwardMessageType), t)) + "//" + "*." + Enum.GetName(typeof(CBExtension), r));

                 }
             }

         }
     }
     catch (Exception ex)
     {
         Common.WriteLog("Exception while listing files in the folder " + Environment.NewLine + ex.Message, ServiceThread.Listing.ToString());

     }
     finally
     {
         DisConnectSftp(_listSftp);
     }

     return ListSFTPFile;

}
#endregion

void client_ListItemReceived(object sender, SftpListItemReceivedEventArgs e)
{

         var listItemReceived = new SftpListItemReceivedEventHandler((s, e1) =>
                      {
                          SftpItem item = e1.Item;

                          objSFTPFile.FileType = Enum.GetName(typeof(InwardMessageType), t);
                          objSFTPFile.Extension = Enum.GetName(typeof(CBExtension), r);
                          objSFTPFile.Status = SFTPStatus.L.ToString();
                          objSFTPFile.FileName = item.Name.Trim();
                          objSFTPFile.FileSize = item.Size;
                          objSFTPFile.Mode = SFTPMode.D.ToString();
                          objSFTPFile.BankCode = Common.BANKCODE;
                          ListSFTPFile.Add(objSFTPFile);
                          Common.WriteLog(MethodInfo.GetCurrentMethod().Name + " FileType: " + objSFTPFile.FileType + " FileName: " + objSFTPFile.FileName, ServiceThread.Listing.ToString());
                          e1.Ignore();
                      });

                     _listSftp.ListItemReceived += client_ListItemReceived;//register
                     _listSftp.GetList(GetSFTPServerPath(Enum.GetName(typeof(InwardMessageType), t)) + "//" + "*." + Enum.GetName(typeof(CBExtension), r));

                 }
             }

         }
    }

Related questions
How to remove memory out exception while fetching large volume of files via SFTP?
How to resolve fetching large volume of files having time out issue from sftp server via Rebex?
How to get some files after fetching files via SFTPItemcollection c#?
How to increase time out for sftp while fetching large volume of files?
Why i am getting "ListTimeout Expired" issue while fetching huge volume of files via sftp?
Welcome to Q&A forum for C# and VB.NET developers working with following .NET components:

Rebex SFTP
Rebex FTP/SSL
Rebex File Server
Rebex Secure Mail
Rebex Terminal
Rebex Security
Rebex Time
Rebex ZIP
If you need immediate assistance, please contact us directly.

Send feedback

Applies to: Rebex SFTP

1 Answer

0 votes
by (144k points)
edited by

There is actually nothing wrong with registering and unregister the event handler before and after each GetList/GetNameList/GetRawList call (unless you need to make it possible to call GetList/GetNameList/GetRawList) call. The overhead is negligible.

However, the ListItemReceived event indeed lacks a way to pass custom parameters from the GetList-calling code, which means you would have to pass them using a field that could be accessed from the event handler as well. This is undesirable, and we will address this in the next release.

Thanks for bringing this issue to our attention, and sorry for the inconvenience!


UPDATE:

From version 2018 R1.1 the UserState property is available in listing event args.

...