Esempio n. 1
0
        private IBaseMessage ProcessMessageInternal(IBaseMessage message, ISftp sftp)
        {
            string filePath = "";

            try
            {
                Stream source = message.BodyPart.Data;
                source.Position = 0;

                if (this._properties.RemoteTempFile.Trim().Length > 0) // Temp dir + Temp file
                {
                    filePath = SftpTransmitProperties.CreateFileName(message, CommonFunctions.CombinePath(this._properties.RemoteTempDir, this._properties.RemoteTempFile));
                }
                else if (this._properties.RemoteTempDir.Trim().Length > 0) // Temp dir + file
                {
                    filePath = SftpTransmitProperties.CreateFileName(message, CommonFunctions.CombinePath(this._properties.RemoteTempDir, this._properties.RemoteFile));
                }
                else // dir + file
                {
                    filePath = SftpTransmitProperties.CreateFileName(message, CommonFunctions.CombinePath(this._properties.RemotePath, this._properties.RemoteFile));
                }

                TraceMessage("[SftpTransmitterEndpoint] Sftp.Put " + filePath);
                sftp.Put(source, filePath);

                // If the RemoteTempDir is set then move the file to the RemotePath
                if (this._properties.RemoteTempDir.Trim().Length > 0)
                {
                    if (this._properties.VerifyFileSize)
                    {
                        VerifyFileSize(sftp, filePath, source.Length); // throws exception if sizes do not match
                    }
                    string toPath = SftpTransmitProperties.CreateFileName(message,
                                                                          CommonFunctions.CombinePath(this._properties.RemotePath, this._properties.RemoteFile));
                    sftp.Rename(filePath, toPath);
                    sftp.ApplySecurityPermissions(this._properties.ApplySecurityPermissions, toPath);
                }
                else
                {
                    sftp.ApplySecurityPermissions(this._properties.ApplySecurityPermissions, filePath);
                }

                return(null);
            }
            catch (Exception ex)
            {
                string innerEx = ex.InnerException == null ? "" : ex.InnerException.Message;
                innerEx += @". Changing any Send Port Transport properties might require the host to be restarted, as the connection pool might still have connections";

                throw new SftpException("[SftpTransmitterEndpoint] Unable to transmit file " + filePath + ".\nInner Exception:\n" + ex.Message + "\n" + innerEx, ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        protected override void HandlerPropertyBagLoaded()
        {
            IPropertyBag config = this.HandlerPropertyBag;

            if (null != config)
            {
                XmlDocument handlerConfigDom = ConfigProperties.IfExistsExtractConfigDom(config);
                if (null != handlerConfigDom)
                {
                    SftpTransmitProperties.ReadTransmitHandlerConfiguration(handlerConfigDom);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Implementation for AsyncTransmitterEndpoint::ProcessMessage
        /// Transmit the message and optionally moves the file from RemoteTempDir to RemotePath
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public override IBaseMessage ProcessMessage(IBaseMessage message)
        {
            this._properties = new SftpTransmitProperties(message, _propertyNamespace);
            ISftp sftp = SftpConnectionPool.GetHostByName(this._properties).GetConnection(this._properties, this._shutdownRequested);

            try
            {
                if (!this._shutdownRequested)
                {
                    ProcessMessageInternal(message, sftp);
                }
            }
            catch (Exception ex)
            {
                //CheckErrorThreshold();
                TraceMessage("[SftpTransmitterEndpoint] Exception: " + ex.Message);
                throw ExceptionHandling.HandleComponentException(System.Reflection.MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                SftpConnectionPool.GetHostByName(this._properties).ReleaseConnection(sftp);
            }
            return(null);
        }