Example #1
0
        public static void ssh_test1()
        {
            SshUserData data1 = new SshUserData();

            data1.user = "******";
            data1.host = "tkynt2.phys.s.u-tokyo.ac.jp";
            data1.port = 22;
            data1.pass = "";

            System.Collections.Hashtable config = new System.Collections.Hashtable();
            config["StrictHostKeyChecking"] = "no";

            SshfsMessage mess1 = new SshfsMessage("[]");

            jsch::JSch    jsch  = new Tamir.SharpSsh.jsch.JSch();
            jsch::Session sess1 = jsch.getSession(data1.user, data1.host, data1.port);

            sess1.setConfig(config);
            //sess1.setUserInfo(new DokanSSHFS.DokanUserInfo(data1.pass,null));
            sess1.setUserInfo(new SshLoginInfo(mess1, data1));
            sess1.setPassword(data1.pass);
            sess1.connect();

            jsch::ChannelExec ch_e = (jsch::ChannelExec)sess1.openChannel("exec");

            ch_e.setCommand("cat");
            ch_e.setOutputStream(System.Console.OpenStandardOutput(), true);
            Tamir.SharpSsh.java.io.InputStream ins = ch_e.getInputStream();
            ch_e.connect();

            System.Console.WriteLine("ls -al ~/");
            System.IO.StreamWriter sw = new System.IO.StreamWriter(ins);
            sw.WriteLine("hello");

            //System.Threading.Thread.Sleep(2000);
            //System.Console.WriteLine("comp.");

            sw.Close();
            ins.close();

            ch_e.disconnect();
            sess1.disconnect();
        }
Example #2
0
        ///<summary>Returns true if the communications were successful, and false if they failed. Both sends and retrieves.</summary>
        public static bool Launch(Clearinghouse clearinghouseClin, int batchNum, IODProgressExtended progress = null)      //called from Eclaims and FormClaimReports.cs. Clinic-level clearinghouse passed in.
        {
            progress           = progress ?? new ODProgressExtendedNull();
            _clearinghouseClin = clearinghouseClin;
            //Before this function is called, the X12 file for the current batch has already been generated in
            //the clearinghouse export folder. The export folder will also contain batch files which have failed
            //to upload from previous attempts and we must attempt to upload these older batch files again if
            //there are any.
            //Step 1: Retrieve reports regarding the existing pending claim statuses.
            //Step 2: Send new claims in a new batch.
            bool success = true;
            //Connect to the MDE SFTP server.
            Session     session = null;
            Channel     channel = null;
            ChannelSftp ch      = null;
            JSch        jsch    = new JSch();

            progress.UpdateProgress(Lans.g(progress.LanThis, "Contacting web server"), "reports", "17%", 17);
            if (progress.IsPauseOrCancel())
            {
                progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                return(false);
            }
            try{
                session = jsch.getSession(_clearinghouseClin.LoginID, remoteHost, 22);
                session.setPassword(_clearinghouseClin.Password);
                Hashtable config = new Hashtable();
                config.Add("StrictHostKeyChecking", "no");
                session.setConfig(config);
                session.connect();
                channel = session.openChannel("sftp");
                channel.connect();
                ch = (ChannelSftp)channel;
            }
            catch (Exception ex) {
                progress.UpdateProgress(Lans.g(progress.LanThis, "Connection Failed"));
                ErrorMessage = Lans.g("MercuryDE", "Connection Failed") + ": " + ex.Message;
                return(false);
            }
            progress.UpdateProgress(Lans.g(progress.LanThis, "Web server contact successful."));
            try{
                //At this point we are connected to the MDE SFTP server.
                if (batchNum == 0)
                {
                    if (!Directory.Exists(clearinghouseClin.ResponsePath))
                    {
                        throw new Exception(Lans.g(progress.LanThis, "Clearinghouse response path is invalid."));
                    }
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Getting files"), "reports", "33%", 33);
                    if (progress.IsPauseOrCancel())
                    {
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                        return(false);
                    }
                    //Only retrieving reports so do not send new claims.
                    string retrievePath = "/" + rootFolderName + "/Out/997/";
                    Tamir.SharpSsh.java.util.Vector fileList = ch.ls(retrievePath);
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        int percent = (i / fileList.Count) * 100;
                        //We re-use the bar again for importing later, hence the tag.
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Getting file:") + i + " / " + fileList.Count, "import", percent + "%", percent);
                        if (progress.IsPauseOrCancel())
                        {
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                            return(false);
                        }
                        string listItem = fileList[i].ToString().Trim();
                        if (listItem[0] == 'd')
                        {
                            continue;                            //Skip directories and focus on files.
                        }
                        Match  fileNameMatch  = Regex.Match(listItem, ".*\\s+(.*)$");
                        string getFileName    = fileNameMatch.Result("$1");
                        string getFilePath    = retrievePath + getFileName;
                        string exportFilePath = CodeBase.ODFileUtils.CombinePaths(clearinghouseClin.ResponsePath, getFileName);
                        Tamir.SharpSsh.java.io.InputStream fileStream = null;
                        FileStream exportFileStream = null;
                        try{
                            fileStream       = ch.get(getFilePath);
                            exportFileStream = File.Open(exportFilePath, FileMode.Create, FileAccess.Write);                        //Creates or overwrites.
                            byte[] dataBytes = new byte[4096];
                            int    numBytes  = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            while (numBytes > 0)
                            {
                                exportFileStream.Write(dataBytes, 0, numBytes);
                                numBytes = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            }
                            float overallpercent = 33 + (i / fileList.Count) * 17;                    //33 is starting point. 17 is the amount of bar space we have before our next major spot (50%)
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Getting files"), "reports", overallpercent + "%", (int)overallpercent);
                            if (progress.IsPauseOrCancel())
                            {
                                progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                                return(false);
                            }
                        }
                        catch (Exception ex) {
                            ErrorMessage = ex.Message;
                            success      = false;
                        }
                        finally {
                            if (exportFileStream != null)
                            {
                                exportFileStream.Dispose();
                            }
                            if (fileStream != null)
                            {
                                fileStream.Dispose();
                            }
                        }
                        string archiveFilePath = retrievePath + "Archive/" + getFileName;
                        try{
                            ch.rm(archiveFilePath);
                        }
                        catch {
                            //Remove any destination files by the same exact name. The file will most likely not be present.
                        }
                        ch.rename(getFilePath, archiveFilePath);
                    }
                }
                else
                {
                    if (!Directory.Exists(clearinghouseClin.ExportPath))
                    {
                        throw new Exception(Lans.g(progress.LanThis, "Clearinghouse export path is invalid."));
                    }
                    //First upload the batch to the temporary directory.
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Uploading files to temp directory"), "reports", "33%", 33);
                    if (progress.IsPauseOrCancel())
                    {
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                        return(false);
                    }
                    string[] files = Directory.GetFiles(clearinghouseClin.ExportPath);
                    for (int i = 0; i < files.Length; i++)
                    {
                        int percent = (i / files.Length) * 100;
                        //We re-use the bar again for importing later, hence the tag.
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Uploading file:") + i + " / " + files.Length, "import", percent + "%", percent);
                        if (progress.IsPauseOrCancel())
                        {
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                            return(false);
                        }
                        string accountNumber      = _clearinghouseClin.ISA08;
                        string dateTimeStr        = DateTime.Now.ToString("yyyyMMddhhmmss");
                        string remoteFileName     = accountNumber + dateTimeStr + i.ToString().PadLeft(3, '0') + ".837D.txt";
                        string remoteTempFilePath = "/" + rootFolderName + "/In/837D/Temp/" + remoteFileName;
                        ch.put(files[i], remoteTempFilePath);
                        //Read, Write and Execute permissions for everyone. This appears to cause no effect.
                        ch.chmod((((7 << 3) | 7) << 3) | 7, remoteTempFilePath);
                        string remoteFilePath = "/" + rootFolderName + "/In/837D/" + remoteFileName;
                        ch.rename(remoteTempFilePath, remoteFilePath);
                        File.Delete(files[i]);                               //Remove the processed file.
                        float overallpercent = 33 + (i / files.Length) * 17; //33 is starting point. 17 is the amount of bar space we have before our next major spot (50%)
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Uploading files"), "reports", overallpercent + "%", (int)overallpercent);
                        if (progress.IsPauseOrCancel())
                        {
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex) {
                if (ErrorMessage != "")
                {
                    ErrorMessage += "\r\n";
                }
                ErrorMessage = ex.Message;
                success      = false;
            }
            finally {
                //Disconnect from the MDE SFTP server.
                progress.UpdateProgress("", "import", "");              //Clear import bar for now.
                channel.disconnect();
                ch.disconnect();
                session.disconnect();
            }
            return(success);
        }
Example #3
0
        ///<summary>Returns true if the communications were successful, and false if they failed. Both sends and retrieves.</summary>
        public static bool Launch(Clearinghouse clearhouse, int batchNum)
        {
            clearinghouse = clearhouse;
            //Before this function is called, the X12 file for the current batch has already been generated in
            //the clearinghouse export folder. The export folder will also contain batch files which have failed
            //to upload from previous attempts and we must attempt to upload these older batch files again if
            //there are any.
            //Step 1: Retrieve reports regarding the existing pending claim statuses.
            //Step 2: Send new claims in a new batch.
            bool success = true;
            //Connect to the Denti-Cal SFTP server.
            Session     session = null;
            Channel     channel = null;
            ChannelSftp ch      = null;
            JSch        jsch    = new JSch();

            try {
                session = jsch.getSession(clearinghouse.LoginID, remoteHost, 22);            //TODO: is this the right port number?
                session.setPassword(clearinghouse.Password);
                Hashtable config = new Hashtable();
                config.Add("StrictHostKeyChecking", "no");
                session.setConfig(config);
                session.connect();
                channel = session.openChannel("sftp");
                channel.connect();
                ch = (ChannelSftp)channel;
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g("DentiCal", "Connection Failed") + ": " + ex.Message);
                return(false);
            }
            try {
                //At this point we are connected to the Denti-Cal SFTP server.
                if (batchNum == 0)                //Retrieve reports.
                {
                    if (!Directory.Exists(clearhouse.ResponsePath))
                    {
                        throw new Exception("Clearinghouse response path is invalid.");
                    }
                    //Only retrieving reports so do not send new claims.
                    string retrievePath = "/Out/";
                    Tamir.SharpSsh.java.util.Vector fileList = ch.ls(retrievePath);
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        string listItem = fileList[i].ToString().Trim();
                        if (listItem[0] == 'd')
                        {
                            continue;                            //Skip directories and focus on files.
                        }
                        Match  fileNameMatch  = Regex.Match(listItem, ".*\\s+(.*)$");
                        string getFileName    = fileNameMatch.Result("$1");
                        string getFilePath    = retrievePath + getFileName;
                        string exportFilePath = CodeBase.ODFileUtils.CombinePaths(clearhouse.ResponsePath, getFileName);
                        Tamir.SharpSsh.java.io.InputStream fileStream = null;
                        FileStream exportFileStream = null;
                        try {
                            fileStream       = ch.get(getFilePath);
                            exportFileStream = File.Open(exportFilePath, FileMode.Create, FileAccess.Write);                        //Creates or overwrites.
                            byte[] dataBytes = new byte[4096];
                            int    numBytes  = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            while (numBytes > 0)
                            {
                                exportFileStream.Write(dataBytes, 0, numBytes);
                                numBytes = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            }
                        }
                        catch {
                            success = false;
                        }
                        finally {
                            if (exportFileStream != null)
                            {
                                exportFileStream.Dispose();
                            }
                            if (fileStream != null)
                            {
                                fileStream.Dispose();
                            }
                        }
                        //TODO: Is the following archive step allowed?
                        if (success)
                        {
                            //Move the processed files into the Archive folder within the Out folder on the Denti-Cal sftp so that history is preserved.
                            string archiveFilePath = retrievePath + "Archive/" + getFileName;
                            try {
                                ch.rm(archiveFilePath);
                            }
                            catch {
                                //Remove any destination files by the same exact name. The file will most likely not be present.
                            }
                            ch.rename(getFilePath, archiveFilePath);
                        }
                    }
                }
                else                   //Send batch of claims.
                {
                    if (!Directory.Exists(clearhouse.ExportPath))
                    {
                        throw new Exception("Clearinghouse export path is invalid.");
                    }
                    //First upload the batch to the temporary directory.
                    string[] files = Directory.GetFiles(clearhouse.ExportPath);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string remoteFileName = "claim" + DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString().PadLeft(5, '0') + ".txt";
                        //TODO:Is a temp subdirectory allowed?
                        string remoteTempFilePath = "/In/Temp/" + remoteFileName;
                        ch.put(files[i], remoteTempFilePath);
                        //Read, Write and Execute permissions for everyone. This appears to cause no effect.
                        ch.chmod((((7 << 3) | 7) << 3) | 7, remoteTempFilePath);
                        string remoteFilePath = "/In/" + remoteFileName;
                        ch.rename(remoteTempFilePath, remoteFilePath);
                        File.Delete(files[i]);                        //Remove the processed file.
                    }
                }
            }
            catch {
                success = false;
            }
            finally {
                //Disconnect from the Denti-Cal SFTP server.
                channel.disconnect();
                ch.disconnect();
                session.disconnect();
            }
            return(success);
        }
Example #4
0
 public void PutWithStream(Tamir.SharpSsh.java.io.InputStream stream, string toDirPath)
 {
     cancelled = false;
     SftpChannel.put(stream, toDirPath, m_monitor);
 }
Example #5
0
        ///<summary>Returns true if the communications were successful, and false if they failed. Both sends and retrieves.</summary>
        public static bool Launch(Clearinghouse clearhouse, int batchNum)
        {
            clearinghouse = clearhouse;
            //Before this function is called, the X12 file for the current batch has already been generated in
            //the clearinghouse export folder. The export folder will also contain batch files which have failed
            //to upload from previous attempts and we must attempt to upload these older batch files again if
            //there are any.
            //Step 1: Retrieve reports regarding the existing pending claim statuses.
            //Step 2: Send new claims in a new batch.
            bool success = true;
            //Connect to the Denti-Cal SFTP server.
            Session     session = null;
            Channel     channel = null;
            ChannelSftp ch      = null;
            JSch        jsch    = new JSch();

            try {
                session = jsch.getSession(clearinghouse.LoginID, remoteHost);
                session.setPassword(clearinghouse.Password);
                Hashtable config = new Hashtable();
                config.Add("StrictHostKeyChecking", "no");
                session.setConfig(config);
                session.connect();
                channel = session.openChannel("sftp");
                channel.connect();
                ch = (ChannelSftp)channel;
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g("DentiCal", "Connection Failed") + ": " + ex.Message);
                return(false);
            }
            try {
                string homeDir = "/Home/" + clearhouse.LoginID + "/";
                //At this point we are connected to the Denti-Cal SFTP server.
                if (batchNum == 0)                //Retrieve reports.
                {
                    if (!Directory.Exists(clearhouse.ResponsePath))
                    {
                        throw new Exception("Clearinghouse response path is invalid.");
                    }
                    //Only retrieving reports so do not send new claims.
                    string retrievePath = homeDir + "out/";
                    Tamir.SharpSsh.java.util.Vector fileList = ch.ls(retrievePath);
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        string listItem = fileList[i].ToString().Trim();
                        if (listItem[0] == 'd')
                        {
                            continue;                            //Skip directories and focus on files.
                        }
                        Match  fileNameMatch  = Regex.Match(listItem, ".*\\s+(.*)$");
                        string getFileName    = fileNameMatch.Result("$1");
                        string getFilePath    = retrievePath + getFileName;
                        string exportFilePath = CodeBase.ODFileUtils.CombinePaths(clearhouse.ResponsePath, getFileName);
                        Tamir.SharpSsh.java.io.InputStream fileStream = null;
                        FileStream exportFileStream = null;
                        try {
                            fileStream       = ch.get(getFilePath);
                            exportFileStream = File.Open(exportFilePath, FileMode.Create, FileAccess.Write);                        //Creates or overwrites.
                            byte[] dataBytes = new byte[4096];
                            int    numBytes  = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            while (numBytes > 0)
                            {
                                exportFileStream.Write(dataBytes, 0, numBytes);
                                numBytes = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            }
                        }
                        catch {
                            success = false;
                        }
                        finally {
                            if (exportFileStream != null)
                            {
                                exportFileStream.Dispose();
                            }
                            if (fileStream != null)
                            {
                                fileStream.Dispose();
                            }
                        }
                        if (success)
                        {
                            //Removed the processed report from the Denti-Cal SFTP so it does not get processed again in the future.
                            try {
                                ch.rm(getFilePath);
                            }
                            catch {
                            }
                        }
                    }
                }
                else                   //Send batch of claims.
                {
                    if (!Directory.Exists(clearhouse.ExportPath))
                    {
                        throw new Exception("Clearinghouse export path is invalid.");
                    }
                    string[] files = Directory.GetFiles(clearhouse.ExportPath);
                    for (int i = 0; i < files.Length; i++)
                    {
                        //First upload the batch file to a temporary file name. Denti-Cal does not process file names unless they start with the Login ID.
                        //Uploading to a temporary file and then renaming the file allows us to avoid partial file uploads if there is connection loss.
                        string tempRemoteFilePath = homeDir + "in/temp_" + Path.GetFileName(files[i]);
                        ch.put(files[i], tempRemoteFilePath);
                        //Denti-Cal requires the file name to start with the Login ID followed by a period and end with a .txt extension.
                        //The middle part of the file name can be anything.
                        string remoteFilePath = homeDir + "in/" + clearhouse.LoginID + "." + Path.GetFileName(files[i]);
                        ch.rename(tempRemoteFilePath, remoteFilePath);
                        File.Delete(files[i]);                        //Remove the processed file.
                    }
                }
            }
            catch {
                success = false;
            }
            finally {
                //Disconnect from the Denti-Cal SFTP server.
                channel.disconnect();
                ch.disconnect();
                session.disconnect();
            }
            return(success);
        }
Example #6
0
        ///<summary>Returns true if the communications were successful, and false if they failed. Both sends and retrieves.</summary>
        public static bool Launch(Clearinghouse clearinghouseClin, int batchNum, IODProgressExtended progress = null)       //called from FormClaimReports and Eclaims.cs. clinic-level clearinghouse passed in.
        //Before this function is called, the X12 file for the current batch has already been generated in
        //the clearinghouse export folder. The export folder will also contain batch files which have failed
        //to upload from previous attempts and we must attempt to upload these older batch files again if
        //there are any.
        //Step 1: Retrieve reports regarding the existing pending claim statuses.
        //Step 2: Send new claims in a new batch.
        {
            progress = progress ?? new ODProgressExtendedNull();
            bool success = true;
            //Connect to the Denti-Cal SFTP server.
            Session     session = null;
            Channel     channel = null;
            ChannelSftp ch      = null;
            JSch        jsch    = new JSch();

            progress.UpdateProgress(Lans.g(progress.LanThis, "Contacting web server"), "reports", "17%", 17);
            if (progress.IsPauseOrCancel())
            {
                progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                return(false);
            }
            try {
                string remoteHost = "mft.oxi.arcaas.com";
                session = jsch.getSession(clearinghouseClin.LoginID, remoteHost);
                session.setPassword(clearinghouseClin.Password);
                Hashtable config = new Hashtable();
                config.Add("StrictHostKeyChecking", "no");
                session.setConfig(config);
                int port = 2222;              //new production port
                session.setPort(port);
                session.connect();
                channel = session.openChannel("sftp");
                channel.connect();
                ch = (ChannelSftp)channel;
            }
            catch (Exception ex) {
                ErrorMessage = Lans.g("DentiCal", "Connection Failed") + ": " + ex.Message;
                return(false);
            }
            progress.UpdateProgress(Lans.g(progress.LanThis, "Web server contact successful."));
            try {
                string homeDir = "/";             //new production home root dir
                //At this point we are connected to the Denti-Cal SFTP server.
                if (batchNum == 0)                //Retrieve reports.
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Downloading reports"), "reports", "33%", 33);
                    if (progress.IsPauseOrCancel())
                    {
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                        return(false);
                    }
                    if (!Directory.Exists(clearinghouseClin.ResponsePath))
                    {
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Clearinghouse response path is invalid."));
                        return(false);

                        throw new Exception("Clearinghouse response path is invalid.");
                    }
                    //Only retrieving reports so do not send new claims.
                    //Although the documentation we received from Denti-Cal says that the folder name should start "OXi", that was not the case for a customer
                    //that we connected to and Barbara Castelli from Denti-Cal informed us that the folder name should start with "dcaprod".
                    string retrievePath = homeDir + "dcaprod_" + clearinghouseClin.LoginID + "_out/";
                    Tamir.SharpSsh.java.util.Vector fileList;
                    try {
                        fileList = ch.ls(retrievePath);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        //Try again with the path as described in the documentation.
                        retrievePath = homeDir + "OXi_" + clearinghouseClin.LoginID + "_out/";
                        fileList     = ch.ls(retrievePath);
                    }
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        int percent = (i / fileList.Count) * 100;
                        //We re-use the bar again for importing later, hence the tag.
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Getting file:") + i + " / " + fileList.Count, "import", percent + "%", percent);
                        if (progress.IsPauseOrCancel())
                        {
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                            return(false);
                        }
                        string listItem = fileList[i].ToString().Trim();
                        if (listItem[0] == 'd')
                        {
                            continue;                            //Skip directories and focus on files.
                        }
                        Match  fileNameMatch  = Regex.Match(listItem, ".*\\s+(.*)$");
                        string getFileName    = fileNameMatch.Result("$1");
                        string getFilePath    = retrievePath + getFileName;
                        string exportFilePath = CodeBase.ODFileUtils.CombinePaths(clearinghouseClin.ResponsePath, getFileName);
                        Tamir.SharpSsh.java.io.InputStream fileStream = null;
                        FileStream exportFileStream = null;
                        try {
                            fileStream       = ch.get(getFilePath);
                            exportFileStream = File.Open(exportFilePath, FileMode.Create, FileAccess.Write);                        //Creates or overwrites.
                            byte[] dataBytes = new byte[4096];
                            int    numBytes  = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            while (numBytes > 0)
                            {
                                exportFileStream.Write(dataBytes, 0, numBytes);
                                numBytes = fileStream.Read(dataBytes, 0, dataBytes.Length);
                            }
                            float overallpercent = 33 + (i / fileList.Count) * 17;                    //33 is starting point. 17 is the amount of bar space we have before our next major spot (50%)
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Getting files"), "reports", overallpercent + "%", (int)overallpercent);
                            if (progress.IsPauseOrCancel())
                            {
                                progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                                return(false);
                            }
                        }
                        catch {
                            success = false;
                        }
                        finally {
                            if (exportFileStream != null)
                            {
                                exportFileStream.Dispose();
                            }
                            if (fileStream != null)
                            {
                                fileStream.Dispose();
                            }
                            progress.UpdateProgress("", "import", "");                          //Clear import bar for now
                        }
                        if (success)
                        {
                            //Removed the processed report from the Denti-Cal SFTP so it does not get processed again in the future.
                            try {
                                ch.rm(getFilePath);
                                progress.UpdateProgress(Lans.g(progress.LanThis, "Reports downloaded successfully."));
                            }
                            catch {
                            }
                        }
                    }
                }
                else                   //Send batch of claims.
                {
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Sending batch of claims"), "reports", "33%", 33);
                    if (progress.IsPauseOrCancel())
                    {
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                        return(false);
                    }
                    if (!Directory.Exists(clearinghouseClin.ExportPath))
                    {
                        throw new Exception(Lans.g(progress.LanThis, "Clearinghouse export path is invalid."));
                    }
                    string[] files = Directory.GetFiles(clearinghouseClin.ExportPath);
                    //Try to find a folder that starts with "dcaprod" or "OXi".
                    string uploadPath = homeDir + "dcaprod_" + clearinghouseClin.LoginID + "_in/";
                    Tamir.SharpSsh.java.util.Vector fileList;
                    try {
                        fileList = ch.ls(uploadPath);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        //Try again with the path as described in the documentation.
                        uploadPath = homeDir + "OXi_" + clearinghouseClin.LoginID + "_in/";
                        fileList   = ch.ls(uploadPath);
                    }
                    //We have successfully found the folder where we need to put the files.
                    for (int i = 0; i < files.Length; i++)
                    {
                        float overallpercent = 33 + (i / files.Length) * 17;                //33 is starting point. 17 is the amount of bar space we have before our next major spot (50%)
                        progress.UpdateProgress(Lans.g(progress.LanThis, "Sending claims"), "reports", overallpercent + "%", (int)overallpercent);
                        if (progress.IsPauseOrCancel())
                        {
                            progress.UpdateProgress(Lans.g(progress.LanThis, "Canceled by user."));
                            return(false);
                        }
                        //First upload the batch file to a temporary file name. Denti-Cal does not process file names unless they start with the Login ID.
                        //Uploading to a temporary file and then renaming the file allows us to avoid partial file uploads if there is connection loss.
                        string tempRemoteFilePath = uploadPath + "temp_" + Path.GetFileName(files[i]);
                        ch.put(files[i], tempRemoteFilePath);
                        //Denti-Cal requires the file name to start with the Login ID followed by a period and end with a .txt extension.
                        //The middle part of the file name can be anything.
                        string remoteFilePath = uploadPath + Path.GetFileName(files[i]);
                        ch.rename(tempRemoteFilePath, remoteFilePath);
                        File.Delete(files[i]);                        //Remove the processed file.
                    }
                    progress.UpdateProgress(Lans.g(progress.LanThis, "Claims sent successfully."));
                }
            }
            catch (Exception ex) {
                success       = false;
                ErrorMessage += ex.Message;
            }
            finally {
                progress.UpdateProgress(Lans.g(progress.LanThis, "Closing connection"), "reports", "50%", 50);
                //Disconnect from the Denti-Cal SFTP server.
                channel.disconnect();
                ch.disconnect();
                session.disconnect();
            }
            return(success);
        }