This project is read-only.

Files not getting uploaded (possibly???)

Feb 14, 2015 at 1:19 AM
I have a very basic routine which is shown below. Everything has been working swimmingly and all seems well. However, I keep having one particular client who is saying my files never make it onto the FTP site because they can't find them. Because all the other clients haven't had this issue, I "suggested" that the problem was on their end. However, today, I received an email from another client who indicated they couldn't find a file. So now I am concerned that something more is maybe going on here. I am not sure. I have sufficient logging in my application to show that a successful "upload path of execution" has occurred for all the missing files (i.e. no errors from the extensive error handling throughout the app and tons of successful logging messages).

I still think the problem might be on their side, but I want to be sure. I am looking for a way to log the interaction between the SftpClient and the server. Is there a way to accomplish this that I am not seeing in the library? What would be great is to be able to get a complete log of the FTP commands issued and the responses from the server. I am not seeing a way to do that. Any suggestions?

If there isn't a way to accomplish that, it would be great to build that into the library so that it could be logged by an app.

Thanks in advance for any help!
        private bool UploadToFtpSite(RunProfile profile, FileInfo x12File, String originalFileName)
        {

            if (profile.SkipUpload)
            {
                log.InfoFormat("Upload of file '{0}' skipped due to configuration item in the '{1}' profile.", x12File.FullName, profile.Description);
                //If the test mode is set to skip, we just return true stating it uploaded.
                return true;

            }


            FtpProfile ftpProfile = GetFtpProfile(profile, originalFileName);

            //only attempt to upload the file if there is a server name, username and password
            if (!String.IsNullOrWhiteSpace(ftpProfile.Server) && !String.IsNullOrWhiteSpace(ftpProfile.UserName) && !String.IsNullOrWhiteSpace(ftpProfile.Password))
            {

                using (SftpClient ftpClient = new SftpClient(ftpProfile.Server, ftpProfile.UserName, ftpProfile.Password))
                {

                    try
                    {
                        ftpClient.Connect();
                        
                        ftpClient.ChangeDirectory(ftpProfile.SubmissionPath);

                        using (var fileStream = new FileStream(x12File.FullName, FileMode.Open))
                        {
                            ftpClient.BufferSize = 4 * 1024; // bypass Payload error for large files
                            ftpClient.UploadFile(fileStream, x12File.Name);
                        }
                        
                        ftpClient.Disconnect();

                        return true;
                    }
                    catch (Exception e)
                    {
                        log.ErrorFormat(String.Format("Unable to upload file '{0}' to FTP server '{1}' from profile '{2}'", x12File.FullName, ftpProfile.Server, profile.Description), e);

                        return false;
                    }
                }

            }
            else
            {
                log.ErrorFormat("No valid ftp server was configured for {0} files in profile '{1}'.  If this is intentional, uncheck the 'Generate {0} file' option in the export profile in QCS.", ftpProfile.Claim ? "Claim" : "Encounter", profile.Description);
                return false;
            }
        }
Feb 24, 2015 at 4:37 PM
You should modify your program and check if your file is available (after upload).
Feb 24, 2015 at 7:12 PM
The client even has a convenient call just for that (it throws an exception if the file can't be found):
Renci.SshNet.Sftp.SftpFile uploadedFile = ftpClient.Get(x12File.Name)