Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Sorry, but no, it does not help. I've tested your code. And as expected, it works. Please post the debug (Session.DebugLogPath) and session (Session.SessionLogPath) logs I've asked for.
NoBullMan

I hope this helps:
public void ConnectSFTP()
{
    // Set up session options
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Sftp,
        HostName = SFTP_Host,
        PortNumber = SFTP_Port,
        UserName = SFTP_UserID,
        Password = SFTP_Password,
        SshHostKeyFingerprint = SFTP_SshHostKeyFingerprint
    };
    sessionOptions.AddRawSettings("Cipher", "aes,chacha20,3des,WARN,des,blowfish,arcfour");
    session = new Session();
    session.ExecutablePath = ExePath;
       
    // Connect
    try
    {
        session.Open(sessionOptions);
        TraceLog.appendTransactionLog("Connected to " + SFTP_Host + ":" + SFTP_Port);
    }
    catch (Exception ex)
    {
        TraceLog.appendTransactionLog("Failed to connect to " + SFTP_Host + ":" + SFTP_Port + " (" + SFTP_SshHostKeyFingerprint + ")" + Environment.NewLine + "Error: " + ex.Message);
    }
}
 
public FileDownloadObj DownloadFiles(DateTime dt)
{
....
    ConnectSFTP();
 
    if (session.Opened)
    {
        using (session)
        {
            sssion.QueryReceived += (sender, e) =>
            {
                sLogText = string.Format("Error: {0}{1}", e.Message, Environment.NewLine);
                TraceLog.appendTransactionLog(sLogText);
                sErrMsg += string.Format("Error: {0}{1}", sLogText, Environment.NewLine); ;
                e.Continue();
            };
            // Transfer options
            TransferOptions oTrRes = new TransferOptions();
            oTrRes.TransferMode = TransferMode.Automatic; //The Transfer Mode - Automatic, Binary, or Ascii
            oTrRes.FilePermissions = null//Permissions applied to remote files; null for default permissions. Can set user, Group, or other Read/Write/Execute permissions. 
            oTrRes.PreserveTimestamp = false//Set last write time of destination file to that of source file - basically change the timestamp to match destination and source files.   
            oTrRes.ResumeSupport.State = TransferResumeSupportState.Off;
 
            // Enumerate files to download
            DateTime dtYesterday = DateTime.Today.AddDays(-1);
            //IEnumerable<RemoteFileInfo> fileInfos2 = session.EnumerateRemoteFiles(sRemotePath, "APBS*.XML", EnumerationOptions.None).Where(file => file.LastWriteTime > dtYesterday);  // Chokes!
 
            IEnumerable<RemoteFileInfo> fileInfos = session.EnumerateRemoteFiles(sRemotePath, "APBS*.XML", WinSCP.EnumerationOptions.None);
martin

Re: "Recursive calls not allowed" error when enumerating files

I cannot imagine the code to be throwing that exception on its own.
Please post complete test code and corresponding session and debug log files.
NoBullMan

"Recursive calls not allowed" error when enumerating files

I have been successfully getting files from remote server up to now. When I tried to add a data range constraints, I keep getting above error message.
// Enumerate files to download
DateTime dtYesterday = DateTime.Today.AddDays(-1);
 
/* This throws error  */
//IEnumerable<RemoteFileInfo> fileInfos2 = session.EnumerateRemoteFiles(sRemotePath, "AP*.XML", EnumerationOptions.None).Where(file => file.LastWriteTime > dtYesterday);
 
/* This works  */
IEnumerable<RemoteFileInfo> fileInfos = session.EnumerateRemoteFiles(sRemotePath, "AP*.XML", WinSCP.EnumerationOptions.None);