public Stream Get(IActivityIOPath path, List<string> filesToCleanup)
        {


            Stream result = null;
            try
            {
                if(IsStandardFtp(path))
                {

                    ReadFromFtp(path, ref result);
                }
                else
                {
                    Dev2Logger.Log.Debug(String.Format("SFTP_GET:{0}", path.Path));
                    ReadFromSftp(path, ref result, filesToCleanup);
                }
            }
            catch(Exception ex)
            {
                Dev2Logger.Log.Error(this, ex);
                var message = string.Format("{0} ,  [{1}]", ex.Message, path.Path);
                throw new Exception(message, ex);
            }
            return result;
        }
        void ReadFromFtp(IActivityIOPath path, ref Stream result)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.UseBinary = true;
            request.KeepAlive = true;
            request.EnableSsl = EnableSsl(path);

            if(path.IsNotCertVerifiable)
            {
                ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
            }

            if(path.Username != string.Empty)
            {
                request.Credentials = new NetworkCredential(path.Username, path.Password);
            }

            using(var response = (FtpWebResponse)request.GetResponse())
            {
                using(var ftpStream = response.GetResponseStream())
                {

                    if(ftpStream != null && ftpStream.CanRead)
                    {
                        byte[] data = ftpStream.ToByteArray();
                        result = new MemoryStream(data);
                    }
                    else
                    {
                        throw new Exception("Fail");
                    }
                }
            }
        }
예제 #3
0
        public Stream Get(IActivityIOPath path, List<string> filesToCleanup)
        {
            Stream result;

            if (!RequiresAuth(path))
            {
                if (File.Exists(path.Path))
                {
                    result = new MemoryStream(File.ReadAllBytes(path.Path));
                }
                else
                {
                    throw new Exception("File not found [ " + path.Path + " ]");
                }
            }
            else
            {
                try
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;

                    string user = ExtractUserName(path);
                    string domain = ExtractDomain(path);
                    bool loginOk = LogonUser(user, domain, path.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                    if (loginOk)
                    {
                        using (safeTokenHandle)
                        {

                            WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                            using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                            {
                                // Do the operation here

                                result = new MemoryStream(File.ReadAllBytes(path.Path));

                                impersonatedUser.Undo(); // remove impersonation now
                            }
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + path.Username + " ] for resource [ " + path.Path + " ] ");
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    throw new Exception(ex.Message, ex);
                }

            }

            return result;
        }
        bool IsFilePresentStandardFtp(IActivityIOPath path)
        {
            FtpWebResponse response = null;

            bool isAlive;

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
                request.Method = WebRequestMethods.Ftp.GetFileSize;
                request.UseBinary = true;
                request.KeepAlive = false;
                request.EnableSsl = EnableSsl(path);

                if(path.Username != string.Empty)
                {
                    request.Credentials = new NetworkCredential(path.Username, path.Password);
                }

                if(path.IsNotCertVerifiable)
                {
                    ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
                }

                using(response = (FtpWebResponse)request.GetResponse())
                {

                    using(Stream responseStream = response.GetResponseStream())
                    {
                        if(responseStream != null)
                        {
                            using(StreamReader reader = new StreamReader(responseStream))
                            {

                                if(reader.EndOfStream)
                                {
                                    // just check for exception, slow I know, but not sure how else to tackle this                  
                                }
                            }
                        }
                    }
                }

                // exception will be thrown if not present
                isAlive = true;
            }
            catch(WebException wex)
            {
                Dev2Logger.Log.Error(this, wex);
                isAlive = false;
            }
            catch(Exception ex)
            {
                Dev2Logger.Log.Error(this, ex);
                throw;
            }
            finally
            {
                if(response != null)
                {
                    response.Close();
                }
            }

            return isAlive;
        }
예제 #5
0
 public int Put(Stream src, IActivityIOPath dst, IDev2CRUDOperationTO args, string whereToPut, List <string> filesToCleanup)
 => new DoPutAction(src, dst, args, whereToPut).ExecuteOperation();
예제 #6
0
 static bool TransferFile(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, string path, IActivityIOPath p, bool result)
 {
     var tmpPath = ActivityIOFactory.CreatePathFromString(path, dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
     var tmpEp = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);
     var whereToPut = GetWhereToPut(src, dst);
     using(var s = src.Get(p, _filesToDelete))
     {
         if(tmpEp.Put(s, tmpEp.IOPath, args, whereToPut, _filesToDelete) < 0)
         {
             result = false;
         }
         s.Close();
         s.Dispose();
     }
     return result;
 }
예제 #7
0
 static bool IsUncFileTypePath(IActivityIOPath src)
 {
     return src.Path.StartsWith(@"\\");
 }
예제 #8
0
        private bool FileExist(IActivityIOPath path)
        {
            bool result = File.Exists(path.Path);

            return result;
        }
예제 #9
0
        public bool CreateDirectory(IActivityIOPath dst, Dev2CRUDOperationTO args)
        {
            bool result = false;

            if (args.Overwrite)
            {
                if (!RequiresAuth(dst))
                {
                    if (DirectoryExist(dst))
                    {
                        Delete(dst);
                    }
                    Directory.CreateDirectory(dst.Path);
                    result = true;
                }
                else
                {
                    try
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {

                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    if (DirectoryExist(dst))
                                    {
                                        Delete(dst);
                                    }
                                    Directory.CreateDirectory(dst.Path);
                                    result = true;

                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                            }
                        }
                        else
                        {
                            // login failed, oh no!
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dev2Logger.Log.Error(ex);
                        throw;
                    }
                }
            }
            else if (!args.Overwrite && !DirectoryExist(dst))
            {
                if (!RequiresAuth(dst))
                {
                    Directory.CreateDirectory(dst.Path);
                    result = true;
                }
                else
                {

                    try
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {

                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    Directory.CreateDirectory(dst.Path);
                                    result = true;

                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                                newID.Dispose();
                            }
                        }
                        else
                        {
                            // login failed
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dev2Logger.Log.Error(ex);
                        throw;
                    }
                }
            }

            return result;
        }
예제 #10
0
        bool IsFilePresentStandardFtp(IActivityIOPath path)
        {
            FtpWebResponse response = null;

            bool isAlive;

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(path.Path));
                request.Method    = WebRequestMethods.Ftp.GetFileSize;
                request.UseBinary = true;
                request.KeepAlive = false;
                request.EnableSsl = EnableSsl(path);

                if (path.Username != string.Empty)
                {
                    request.Credentials = new NetworkCredential(path.Username, path.Password);
                }

                if (path.IsNotCertVerifiable)
                {
                    ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
                }

                using (response = (FtpWebResponse)request.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (responseStream != null)
                        {
                            using (StreamReader reader = new StreamReader(responseStream))
                            {
                                if (reader.EndOfStream)
                                {
                                    // just check for exception, slow I know, but not sure how else to tackle this
                                }
                            }
                        }
                    }
                }

                // exception will be thrown if not present
                isAlive = true;
            }
            catch (WebException wex)
            {
                Dev2Logger.Log.Error(this, wex);
                isAlive = false;
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(this, ex);
                throw;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(isAlive);
        }
예제 #11
0
        // TODO : Implement as per Unlimited.Framework.Plugins.FileSystem in the Unlimited.Framework.Plugins project
        // Make sure to replace Uri with IActivity references

        public bool PathExist(IActivityIOPath dst)
        {
            var result = PathIs(dst) == enPathType.Directory ? IsDirectoryAlreadyPresent(dst) : IsFilePresent(dst);

            return(result);
        }
예제 #12
0
        IList <IActivityIOPath> ListDirectoryStandardFtp(IActivityIOPath src)
        {
            List <IActivityIOPath> result   = new List <IActivityIOPath>();
            FtpWebResponse         response = null;

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(src.Path));
                request.Method    = WebRequestMethods.Ftp.ListDirectory;
                request.UseBinary = true;
                request.KeepAlive = false;
                request.EnableSsl = EnableSsl(src);

                if (src.Username != string.Empty)
                {
                    request.Credentials = new NetworkCredential(src.Username, src.Password);
                }

                if (src.IsNotCertVerifiable)
                {
                    ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
                }

                using (response = (FtpWebResponse)request.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (responseStream != null)
                        {
                            using (StreamReader reader = new StreamReader(responseStream))
                            {
                                while (!reader.EndOfStream)
                                {
                                    string uri = BuildValidPathForFtp(src, reader.ReadLine());
                                    result.Add(ActivityIOFactory.CreatePathFromString(uri, src.Username, src.Password, true));
                                }
                            }
                        }
                    }
                }
            }
            catch (WebException webEx)
            {
                FtpWebResponse webResponse = webEx.Response as FtpWebResponse;
                if (webResponse != null)
                {
                    if (webResponse.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                    {
                        throw new DirectoryNotFoundException(string.Format("Directory '{0}' was not found", src.Path));
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(this, ex);
                throw;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(result);
        }
예제 #13
0
 public IList <IActivityIOPath> ListDirectory(IActivityIOPath src)
 {
     return(IsStandardFtp(src) ? ListDirectoryStandardFtp(src) : ListDirectorySftp(src));
 }
예제 #14
0
        private bool IsDirectoryAlreadyPresent(IActivityIOPath path)
        {
            var isAlive = IsStandardFtp(path) ? IsDirectoryAlreadyPresentStandardFtp(path) : IsDirectoryAlreadyPresentSftp(path);

            return(isAlive);
        }
예제 #15
0
        private static bool EnableSsl(IActivityIOPath path)
        {
            var result = path.PathType == enActivityIOPathType.FTPS || path.PathType == enActivityIOPathType.FTPES;

            return(result);
        }
예제 #16
0
 public IList <IActivityIOPath> ListDirectory(IActivityIOPath src)
 => new DoGetFilesAsPerTypeOperation(src, ReadTypes.FilesAndFolders).ExecuteOperation();
예제 #17
0
 public bool CreateDirectory(IActivityIOPath dst, IDev2CRUDOperationTO args)
 => new DoCreateDirectory(dst, args).ExecuteOperation();
예제 #18
0
        protected override IList <OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update)
        {
            IsNotCertVerifiable = true;

            allErrors = new ErrorResultTO();
            IList <OutputTO> outputs = new List <OutputTO>();

            var colItr = new WarewolfListIterator();

            //get all the possible paths for all the string variables
            var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update));

            colItr.AddVariableToIterateOn(inputItr);

            var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update));

            colItr.AddVariableToIterateOn(unameItr);

            var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword, update));

            colItr.AddVariableToIterateOn(passItr);

            var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update));

            colItr.AddVariableToIterateOn(privateKeyItr);

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update);
                AddDebugInputItem(new DebugItemStaticDataParams(GetReadType().GetDescription(), "Read"));
                AddDebugInputItemUserNamePassword(dataObject.Environment, update);
                if (!string.IsNullOrEmpty(PrivateKeyFile))
                {
                    AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update);
                }
            }

            while (colItr.HasMoreData())
            {
                IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker();
                IActivityIOPath           ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr),
                                                                                          colItr.FetchNextValue(unameItr),
                                                                                          colItr.FetchNextValue(passItr),
                                                                                          true, colItr.FetchNextValue(privateKeyItr));
                IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath);

                try
                {
                    IList <IActivityIOPath> listOfDir = broker.ListDirectory(endPoint, GetReadType());
                    if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric)
                    {
                        if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star)
                        {
                            string recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result);
                            string fieldName  = DataListUtil.ExtractFieldNameFromValue(Result);

                            int indexToUpsertTo = 1;
                            if (listOfDir != null)
                            {
                                foreach (IActivityIOPath pa in listOfDir)
                                {
                                    string fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName,
                                                                                                     indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), pa.Path));
                                    indexToUpsertTo++;
                                }
                            }
                        }
                        else if (DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Blank)
                        {
                            if (listOfDir != null)
                            {
                                foreach (IActivityIOPath pa in listOfDir)
                                {
                                    outputs.Add(DataListFactory.CreateOutputTO(Result, pa.Path));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (listOfDir != null)
                        {
                            string xmlList = string.Join(",", listOfDir.Select(c => c.Path));
                            outputs.Add(DataListFactory.CreateOutputTO(Result));
                            outputs.Last().OutputStrings.Add(xmlList);
                        }
                    }
                }
                catch (Exception e)
                {
                    outputs.Add(DataListFactory.CreateOutputTO(null));
                    allErrors.AddError(e.Message);
                    break;
                }
            }

            return(outputs);
        }
예제 #19
0
 public static bool IsNotFtpTypePath(IActivityIOPath src) => !src.Path.ToLower().StartsWith("ftp://".ToLower()) &&
 !src.Path.ToLower().StartsWith("ftps://".ToLower()) &&
 !src.Path.ToLower().StartsWith("sftp://".ToLower());
예제 #20
0
 static bool IsStandardFtp(IActivityIOPath path)
 {
     return(path.PathType == enActivityIOPathType.FTP || path.PathType == enActivityIOPathType.FTPES || path.PathType == enActivityIOPathType.FTPS);
 }
예제 #21
0
        public bool Delete(IActivityIOPath src)
        {
            bool result;
            try
            {

                if (!RequiresAuth(src))
                {
                    // We need sense check the value passed in ;)
                    result = DeleteHelper.Delete(src.Path);
                }
                else
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;
                    bool loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                    if (loginOk)
                    {
                        using (safeTokenHandle)
                        {

                            WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                            using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                            {
                                // Do the operation here

                                result = DeleteHelper.Delete(src.Path);


                                // remove impersonation now
                                impersonatedUser.Undo();
                            }
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + src.Username + " ] for resource [ " + src.Path + " ] ");
                    }
                }

            }
            catch (Exception)
            {
                //File is not found problem during delete
                result = false;
            }
            return result;
        }
예제 #22
0
 internal bool DeleteOp(IActivityIOPath src)
 {
     return(IsStandardFtp(src) ? DeleteUsingStandardFtp(src) : DeleteUsingSftp(src));
 }
예제 #23
0
 /// <summary>
 /// Get folder listing for source
 /// </summary>
 /// <returns></returns>
 public IList<IActivityIOPath> ListFilesInDirectory(IActivityIOPath src)
 {
     return ListDirectoriesAccordingToType(src, ReadTypes.Files);
 }
예제 #24
0
 bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result)
 {
     try
     {
         if (dst.PathIs(dst.IOPath) == enPathType.Directory)
         {
             var cpPath =
                 ActivityIOFactory.CreatePathFromString(
                     $"{origDstPath}{dst.PathSeperator()}{Dev2ActivityIOPathUtils.ExtractFileName(p.Path)}",
                     dst.IOPath.Username,
                     dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
             var path = cpPath.Path;
             DoFileTransfer(src, dst, args, cpPath, p, path, ref result);
         }
         else
         {
             if (args.Overwrite || !dst.PathExist(dst.IOPath))
             {
                 var tmp  = origDstPath + @"\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path);
                 var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile);
                 DoFileTransfer(src, dst, args, path, p, path.Path, ref result);
             }
         }
     }
     catch (Exception ex)
     {
         Dev2Logger.Error(ex, GlobalConstants.WarewolfError);
     }
     return(result);
 }
예제 #25
0
 public bool PathExist(IActivityIOPath dst)
 => new DoPathExistOperation(dst).ExecuteOperation();
예제 #26
0
 void DoFileTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, IActivityIOPath dstPath, IActivityIOPath p, string path, ref bool result)
 {
     if (args.Overwrite || !dst.PathExist(dstPath))
     {
         result = TransferFile(src, dst, args, path, p, ref result);
     }
 }
예제 #27
0
 static bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result)
 {
     try
     {
         if(dst.PathIs(dst.IOPath) == enPathType.Directory)
         {
             var cpPath =
                 ActivityIOFactory.CreatePathFromString(
                     string.Format("{0}{1}{2}", origDstPath, dst.PathSeperator(),
                         Dev2ActivityIOPathUtils.ExtractFileName(p.Path)),
                     dst.IOPath.Username,
                     dst.IOPath.Password, true,dst.IOPath.PrivateKeyFile);
             var path = cpPath.Path;
             DoFileTransfer(src, dst, args, cpPath, p, path, ref result);
         }
         else if(args.Overwrite || !dst.PathExist(dst.IOPath))
         {
             var tmp = origDstPath + "\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path);
             var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile);
             DoFileTransfer(src, dst, args, path, p, path.Path, ref result);
         }
     }
     catch(Exception ex)
     {
         Dev2Logger.Log.Error(ex);
     }
     return result;
 }
예제 #28
0
        bool TransferFile(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, string path, IActivityIOPath p, ref bool result)
        {
            var tmpPath    = ActivityIOFactory.CreatePathFromString(path, dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
            var tmpEp      = ActivityIOFactory.CreateOperationEndPointFromIOPath(tmpPath);
            var whereToPut = GetWhereToPut(src, dst);

            using (var s = src.Get(p, _filesToDelete))
            {
                if (tmpEp.Put(s, tmpEp.IOPath, args, whereToPut, _filesToDelete) < 0)
                {
                    result = false;
                }
                s.Close();
                s.Dispose();
            }
            return(result);
        }
        private void BootstrapPersistence(string baseDir)
        {
            lock (InitLock)
            {
                if (_debugPath == null)
                {
                    if (baseDir != null)
                    {
                        _rootPath = baseDir;
                    }

                    if (_rootPath.EndsWith("\\"))
                    {
                        _debugPersistPath = _rootPath + SavePath;
                    }
                    else
                    {
                        _debugPersistPath = _rootPath + "\\" + SavePath;
                    }

                    _debugPath = ActivityIOFactory.CreatePathFromString(_debugPersistPath, "", "","");
                    _debugOptsEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(_debugPath);
                }
            }
        }
예제 #30
0
 public static SafeTokenHandle DoLogOn(IDev2LogonProvider dev2Logon, IActivityIOPath path) => dev2Logon.DoLogon(path);
 private bool IsFilePresent(IActivityIOPath path)
 {
     var isFilePresent = IsStandardFtp(path) ? IsFilePresentStandardFtp(path) : IsFilePresentSftp(path);
     return isFilePresent;
 }
예제 #32
0
        public int Put(Stream src, IActivityIOPath dst, Dev2CRUDOperationTO args, string whereToPut, List <string> filesToCleanup)
        {
            int result = -1;

            using (src)
            {
                //2013.05.29: Ashley Lewis for bug 9507 - default destination to source directory when destination is left blank or if it is not a rooted path
                if (!Path.IsPathRooted(dst.Path))
                {
                    //get just the directory path to put into
                    if (whereToPut != null)
                    {
                        //Make the destination directory equal to that directory
                        dst = ActivityIOFactory.CreatePathFromString(whereToPut + "\\" + dst.Path, dst.Username, dst.Password);
                    }
                }

                if ((args.Overwrite) || (!args.Overwrite && !FileExist(dst)))
                {
                    if (!RequiresAuth(dst))
                    {
                        using (src)
                        {
                            File.WriteAllBytes(dst.Path, src.ToByteArray());
                            result = (int)src.Length;
                        }
                    }
                    else
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool            loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {
                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    using (src)
                                    {
                                        File.WriteAllBytes(dst.Path, src.ToByteArray());
                                        result = (int)src.Length;
                                    }


                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                            }
                        }
                        else
                        {
                            // login failed
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                }
            }

            return(result);
        }
예제 #33
0
        protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context,
                                                                  out ErrorResultTO allErrors)
        {
            IList <OutputTO>  outputs    = new List <OutputTO>();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = dataObject.DataListID;

            ColItr = Dev2ValueObjectFactory.CreateIteratorCollection();

            //get all the possible paths for all the string variables
            IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, InputPath, false,
                                                                    out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry);

            ColItr.AddIterator(inputItr);

            IBinaryDataListEntry outputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, false,
                                                                     out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator outputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(outputPathEntry);

            ColItr.AddIterator(outputItr);

            IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false,
                                                                   out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry);

            ColItr.AddIterator(unameItr);

            IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false,
                                                                   out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry);

            ColItr.AddIterator(passItr);

            IBinaryDataListEntry destinationUsernameEntry = compiler.Evaluate(executionId, enActionType.User, DestinationUsername, false,
                                                                              out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator desunameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationUsernameEntry);

            ColItr.AddIterator(desunameItr);

            IBinaryDataListEntry destinationPasswordEntry = compiler.Evaluate(executionId, enActionType.User, DestinationPassword, false,
                                                                              out errors);

            allErrors.MergeErrors(errors);
            IDev2DataListEvaluateIterator despassItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationPasswordEntry);

            ColItr.AddIterator(despassItr);

            var iteratorsErrors = new List <ErrorResultTO>();

            AddItemsToIterator(executionId, compiler, iteratorsErrors);
            ErrorResultTO to = allErrors;

            iteratorsErrors.ForEach(to.MergeErrors);

            outputs.Add(DataListFactory.CreateOutputTO(Result));

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugItemVariableParams(InputPath, "Source Path", inputPathEntry, executionId));
                AddDebugInputItemUserNamePassword(executionId, usernameEntry);
                AddDebugInputItem(new DebugItemVariableParams(OutputPath, "Destination Path", outputPathEntry, executionId));
                AddDebugInputItemDestinationUsernamePassword(executionId, destinationUsernameEntry, DestinationPassword, DestinationUsername);
                AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite"));
                AddDebugInputItems(executionId);
            }

            while (ColItr.HasMoreData())
            {
                var             hasError = false;
                IActivityIOPath src      = null;
                IActivityIOPath dst      = null;
                try
                {
                    src = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(inputItr).TheValue,
                                                                 ColItr.FetchNextRow(unameItr).TheValue,
                                                                 ColItr.FetchNextRow(passItr).TheValue,
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Source: " + ioException.Message);
                    hasError = true;
                }
                try
                {
                    dst = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(outputItr).TheValue,
                                                                 ColItr.FetchNextRow(desunameItr).TheValue,
                                                                 ColItr.FetchNextRow(despassItr).TheValue,
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Destination:" + ioException.Message);
                    hasError = true;
                }

                if (hasError)
                {
                    outputs[0].OutputStrings.Add(null);
                    MoveRemainingIterators();
                    continue;
                }
                IActivityIOOperationsEndPoint scrEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(src);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);

                try
                {
                    IActivityOperationsBroker broker = GetOperationBroker();
                    var result = ExecuteBroker(broker, scrEndPoint, dstEndPoint);
                    outputs[0].OutputStrings.Add(result);
                }
                catch (Exception e)
                {
                    allErrors.AddError(e.Message);
                    outputs[0].OutputStrings.Add(null);
                }
            }

            return(outputs);
        }
예제 #34
0
        public bool CreateDirectory(IActivityIOPath dst, Dev2CRUDOperationTO args)
        {
            bool result = false;

            if (args.Overwrite)
            {
                if (!RequiresAuth(dst))
                {
                    if (DirectoryExist(dst))
                    {
                        Delete(dst);
                    }
                    Directory.CreateDirectory(dst.Path);
                    result = true;
                }
                else
                {
                    try
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool            loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {
                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    if (DirectoryExist(dst))
                                    {
                                        Delete(dst);
                                    }
                                    Directory.CreateDirectory(dst.Path);
                                    result = true;

                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                            }
                        }
                        else
                        {
                            // login failed, oh no!
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dev2Logger.Log.Error(ex);
                        throw;
                    }
                }
            }
            else if (!args.Overwrite && !DirectoryExist(dst))
            {
                if (!RequiresAuth(dst))
                {
                    Directory.CreateDirectory(dst.Path);
                    result = true;
                }
                else
                {
                    try
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool            loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {
                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    Directory.CreateDirectory(dst.Path);
                                    result = true;

                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                                newID.Dispose();
                            }
                        }
                        else
                        {
                            // login failed
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dev2Logger.Log.Error(ex);
                        throw;
                    }
                }
            }

            return(result);
        }
        protected override IList <OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject,
                                                                  out ErrorResultTO allErrors)
        {
            IList <OutputTO> outputs = new List <OutputTO>();

            allErrors = new ErrorResultTO();
            ColItr    = new WarewolfListIterator();

            //get all the possible paths for all the string variables
            var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath));

            ColItr.AddVariableToIterateOn(inputItr);


            var outputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath));

            ColItr.AddVariableToIterateOn(outputItr);


            var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username));

            ColItr.AddVariableToIterateOn(unameItr);


            var passItr = new WarewolfIterator(dataObject.Environment.Eval(Password));

            ColItr.AddVariableToIterateOn(passItr);


            var desunameItr = new WarewolfIterator(dataObject.Environment.Eval(DestinationUsername));

            ColItr.AddVariableToIterateOn(desunameItr);


            var despassItr = new WarewolfIterator(dataObject.Environment.Eval(DestinationPassword));

            ColItr.AddVariableToIterateOn(despassItr);

            AddItemsToIterator(dataObject.Environment);

            outputs.Add(DataListFactory.CreateOutputTO(Result));

            if (dataObject.IsDebugMode())
            {
                AddDebugInputItem(new DebugEvalResult(InputPath, "Source Path", dataObject.Environment));
                AddDebugInputItemUserNamePassword(dataObject.Environment);
                AddDebugInputItem(new DebugEvalResult(OutputPath, "Destination Path", dataObject.Environment));
                AddDebugInputItemDestinationUsernamePassword(dataObject.Environment, DestinationPassword, DestinationUsername);
                AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite"));
                AddDebugInputItems(dataObject.Environment);
            }

            while (ColItr.HasMoreData())
            {
                var             hasError = false;
                IActivityIOPath src      = null;
                IActivityIOPath dst      = null;
                try
                {
                    src = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextValue(inputItr),
                                                                 ColItr.FetchNextValue(unameItr),
                                                                 ColItr.FetchNextValue(passItr),
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Source: " + ioException.Message);
                    hasError = true;
                }
                try
                {
                    dst = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextValue(outputItr),
                                                                 ColItr.FetchNextValue(desunameItr),
                                                                 ColItr.FetchNextValue(despassItr),
                                                                 true);
                }
                catch (IOException ioException)
                {
                    allErrors.AddError("Destination:" + ioException.Message);
                    hasError = true;
                }

                if (hasError)
                {
                    outputs[0].OutputStrings.Add(null);
                    MoveRemainingIterators();
                    continue;
                }
                IActivityIOOperationsEndPoint scrEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(src);
                IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst);

                try
                {
                    IActivityOperationsBroker broker = GetOperationBroker();
                    var result = ExecuteBroker(broker, scrEndPoint, dstEndPoint);
                    outputs[0].OutputStrings.Add(result);
                }
                catch (Exception e)
                {
                    allErrors.AddError(e.Message);
                    outputs[0].OutputStrings.Add(null);
                }
            }

            return(outputs);
        }
예제 #36
0
 /// <summary>
 /// Get folder listing for source
 /// </summary>
 /// <returns></returns>
 public IList <IActivityIOPath> ListFilesInDirectory(IActivityIOPath src)
 {
     return(ListDirectoriesAccordingToType(src, ReadTypes.Files));
 }
예제 #37
0
        private bool IsFilePresent(IActivityIOPath path)
        {
            var isFilePresent = IsStandardFtp(path) ? IsFilePresentStandardFtp(path) : IsFilePresentSftp(path);

            return(isFilePresent);
        }
예제 #38
0
        private bool FileExist(IActivityIOPath path)
        {
            bool result = File.Exists(path.Path);

            return(result);
        }
예제 #39
0
        public int Put(Stream src, IActivityIOPath dst, Dev2CRUDOperationTO args, string whereToPut, List<string> filesToCleanup)
        {
            int result = -1;
            using (src)
            {
                //2013.05.29: Ashley Lewis for bug 9507 - default destination to source directory when destination is left blank or if it is not a rooted path
                if (!Path.IsPathRooted(dst.Path))
                {
                    //get just the directory path to put into
                    if (whereToPut != null)
                    {
                        //Make the destination directory equal to that directory
                        dst = ActivityIOFactory.CreatePathFromString(whereToPut + "\\" + dst.Path, dst.Username, dst.Password,dst.PrivateKeyFile);
                    }
                }
                if (args.Overwrite || !args.Overwrite && !FileExist(dst))
                {
                    _fileLock.EnterWriteLock();
                    try
                    {
                        if (!RequiresAuth(dst))
                        {
                            using (src)
                            {
                                File.WriteAllBytes(dst.Path, src.ToByteArray());
                                result = (int)src.Length;
                            }
                        }
                        else
                        {
                            // handle UNC path
                            SafeTokenHandle safeTokenHandle;
                            bool loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                            if (loginOk)
                            {
                                using (safeTokenHandle)
                                {

                                    WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                    using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                    {
                                        // Do the operation here
                                        using (src)
                                        {
                                            File.WriteAllBytes(dst.Path, src.ToByteArray());
                                            result = (int)src.Length;
                                        }

                                        // remove impersonation now
                                        impersonatedUser.Undo();
                                    }
                                }
                            }
                            else
                            {
                                // login failed
                                throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                            }
                        }
                    }
                    finally
                    {
                        _fileLock.ExitWriteLock();
                    }
                }
            }
            return result;
        }
예제 #40
0
        private bool DirectoryExist(IActivityIOPath dir)
        {
            bool result = Directory.Exists(dir.Path);

            return(result);
        }
예제 #41
0
        public bool PathExist(IActivityIOPath dst)
        {
            bool result;

            if (!RequiresAuth(dst))
            {
                result = PathIs(dst) == enPathType.Directory ? Directory.Exists(dst.Path) : File.Exists(dst.Path);
            }
            else
            {

                try
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;
                    bool loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                    if (loginOk)
                    {
                        using (safeTokenHandle)
                        {

                            WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                            using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                            {
                                // Do the operation here

                                result = PathIs(dst) == enPathType.Directory ? Directory.Exists(dst.Path) : File.Exists(dst.Path);

                                // remove impersonation now
                                impersonatedUser.Undo();
                            }
                            newID.Dispose();
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    throw;
                }
            }

            return result;
        }
예제 #42
0
        private bool RequiresAuth(IActivityIOPath path)
        {
            bool result = path.Username != string.Empty;

            return(result);
        }
예제 #43
0
        public enPathType PathIs(IActivityIOPath path)
        {
            enPathType result = enPathType.File;

            if (path.Path.StartsWith("\\\\"))
            {
                if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                {
                    result = enPathType.Directory;
                }
            }
            else
            {
                //  && FileExist(path)
                if (FileExist(path) || DirectoryExist(path))
                {
                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path.Path))
                    {
                        FileAttributes fa = File.GetAttributes(path.Path);

                        if ((fa & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            result = enPathType.Directory;
                        }
                    }
                }
                else
                {
                    if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                    {
                        result = enPathType.Directory;
                    }
                }
            }

            return result;
        }
예제 #44
0
        private IList <IActivityIOPath> ListDirectoriesAccordingToType(IActivityIOPath src, ReadTypes type)
        {
            IList <IActivityIOPath> result = new List <IActivityIOPath>();

            string path = src.Path;

            if (!path.EndsWith("\\") && PathIs(src) == enPathType.Directory)
            {
                path += "\\";
            }

            if (!RequiresAuth(src))
            {
                try
                {
                    IEnumerable <string> dirs;

                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path))
                    {
                        if (Directory.Exists(path))
                        {
                            dirs = GetDirectoriesForType(path, string.Empty, type);
                        }
                        else
                        {
                            throw new Exception("The Directory does not exist.");
                        }
                    }
                    else
                    {
                        // we have a wild-char path ;)
                        string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path);
                        string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path);

                        dirs = GetDirectoriesForType(baseDir, pattern, type);
                    }

                    if (dirs != null)
                    {
                        foreach (string d in dirs)
                        {
                            result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, true));
                        }
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Directory not found [ " + src.Path + " ] ");
                }
            }
            else
            {
                try
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;
                    bool            loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                    if (loginOk)
                    {
                        using (safeTokenHandle)
                        {
                            WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                            using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                            {
                                // Do the operation here

                                try
                                {
                                    IEnumerable <string> dirs;

                                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path))
                                    {
                                        dirs = GetDirectoriesForType(path, string.Empty, type);
                                    }
                                    else
                                    {
                                        // we have a wild-char path ;)
                                        string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path);
                                        string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path);

                                        dirs = GetDirectoriesForType(baseDir, pattern, type);
                                    }

                                    if (dirs != null)
                                    {
                                        foreach (string d in dirs)
                                        {
                                            result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password));
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    throw new Exception("Directory not found [ " + src.Path + " ] ");
                                }

                                // remove impersonation now
                                impersonatedUser.Undo();
                                newID.Dispose();
                            }
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + src.Username + " ] for resource [ " + src.Path + " ] ");
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    throw;
                }
            }

            return(result);
        }
예제 #45
0
        private string ExtractDomain(IActivityIOPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            string result = string.Empty;

            int idx = path.Username.IndexOf("\\", StringComparison.Ordinal);

            if (idx > 0)
            {
                result = path.Username.Substring(0, idx);
            }

            return result;
        }
예제 #46
0
        private bool RequiresAuth(IActivityIOPath path)
        {
            bool result = path.Username != string.Empty;

            return result;
        }
예제 #47
0
 private bool DirectoryExist(IActivityIOPath dir)
 {
     bool result = Directory.Exists(dir.Path);
     return result;
 }
예제 #48
0
 public bool Delete(IActivityIOPath src)
 => new DoDeleteOperation(src).ExecuteOperation();
예제 #49
0
        private IList<IActivityIOPath> ListDirectoriesAccordingToType(IActivityIOPath src, ReadTypes type)
        {
            IList<IActivityIOPath> result = new List<IActivityIOPath>();

            string path = src.Path;

            if (!path.EndsWith("\\") && PathIs(src) == enPathType.Directory)
            {
                path += "\\";
            }

            if (!RequiresAuth(src))
            {
                try
                {

                    IEnumerable<string> dirs;

                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path))
                    {
                        if (Directory.Exists(path))
                        {
                            dirs = GetDirectoriesForType(path, string.Empty, type);
                        }
                        else
                        {
                            throw new Exception("The Directory does not exist.");
                        }
                    }
                    else
                    {
                        // we have a wild-char path ;)
                        string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path);
                        string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path);

                        dirs = GetDirectoriesForType(baseDir, pattern, type);
                    }

                    if (dirs != null)
                    {
                        foreach (string d in dirs)
                        {
                            result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, true,src.PrivateKeyFile));
                        }
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Directory not found [ " + src.Path + " ] ");
                }
            }
            else
            {

                try
                {
                    // handle UNC path
                    SafeTokenHandle safeTokenHandle;
                    bool loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                    if (loginOk)
                    {
                        using (safeTokenHandle)
                        {

                            WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                            using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                            {
                                // Do the operation here

                                try
                                {

                                    IEnumerable<string> dirs;

                                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path))
                                    {
                                        dirs = GetDirectoriesForType(path, string.Empty, type);
                                    }
                                    else
                                    {
                                        // we have a wild-char path ;)
                                        string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path);
                                        string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path);

                                        dirs = GetDirectoriesForType(baseDir, pattern, type);
                                    }

                                    if (dirs != null)
                                    {
                                        foreach (string d in dirs)
                                        {
                                            result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, src.PrivateKeyFile));
                                        }
                                    }

                                }
                                catch (Exception)
                                {
                                    throw new Exception("Directory not found [ " + src.Path + " ] ");
                                }

                                // remove impersonation now
                                impersonatedUser.Undo();
                                newID.Dispose();
                            }
                        }
                    }
                    else
                    {
                        // login failed
                        throw new Exception("Failed to authenticate with user [ " + src.Username + " ] for resource [ " + src.Path + " ] ");
                    }
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    throw;
                }

            }

            return result;
        }
 static bool IsStandardFtp(IActivityIOPath path)
 {
     return path.PathType == enActivityIOPathType.FTP || path.PathType == enActivityIOPathType.FTPES || path.PathType == enActivityIOPathType.FTPS;
 }
예제 #51
0
 static bool IsNotFtpTypePath(IActivityIOPath src)
 {
     return !src.Path.StartsWith("ftp://") && !src.Path.StartsWith("ftps://") && !src.Path.StartsWith("sftp://");
 }
 internal bool DeleteOp(IActivityIOPath src)
 {
     return IsStandardFtp(src) ? DeleteUsingStandardFtp(src) : DeleteUsingSftp(src);
 }
예제 #53
0
        IList<string> MakeDirectoryParts(IActivityIOPath path, string splitter)
        {
            string[] tmp;

            IList<string> result = new List<string>();

            var splitOn = splitter.ToCharArray();

            if(IsNotFtpTypePath(path))
            {
                tmp = path.Path.Split(splitOn);

            }
            else
            {
                var splitValues = path.Path.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                splitValues.RemoveAt(0);
                var newPath = string.Join("/", splitValues);
                tmp = newPath.Split(splitOn);
            }

            // remove trailing file entry if exist
            var candiate = tmp[tmp.Length - 1];
            var len = tmp.Length;
            if(candiate.Contains("*.") || candiate.Contains("."))
            {
                len = tmp.Length - 1;
            }

            var builderPath = "";
            // build up URI parts from root down
            for(var i = 0; i < len; i++)
            {
                if(!string.IsNullOrWhiteSpace(tmp[i]))
                {
                    builderPath += tmp[i] + splitter;
                    if(!IsNotFtpTypePath(path) && !builderPath.Contains("://"))
                    {
                        var splitValues = path.Path.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        builderPath = splitValues[0] + "://" + builderPath;
                    }
                    result.Add(IsUncFileTypePath(path) ? @"\\" + builderPath : builderPath);
                }
            }
            return result;
        }
        bool DeleteUsingStandardFtp(IActivityIOPath src)
        {
            FtpWebResponse response = null;

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConvertSslToPlain(src.Path));

                request.Method = PathIs(src) == enPathType.Directory ? WebRequestMethods.Ftp.RemoveDirectory : WebRequestMethods.Ftp.DeleteFile;

                request.UseBinary = true;
                request.KeepAlive = false;
                request.EnableSsl = EnableSsl(src);

                if(src.IsNotCertVerifiable)
                {
                    ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
                }

                if(src.Username != string.Empty)
                {
                    request.Credentials = new NetworkCredential(src.Username, src.Password);
                }

                using(response = (FtpWebResponse)request.GetResponse())
                {
                    if(response.StatusCode != FtpStatusCode.FileActionOK)
                    {
                        throw new Exception("Fail");
                    }
                }
            }
            catch(Exception exception)
            {
                throw new Exception(string.Format("Could not delete {0}. Please check the path exists.", src.Path), exception);
            }
            finally
            {
                if(response != null)
                {
                    response.Close();
                }
            }
            return true;
        }
예제 #55
0
 static void DoFileTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, Dev2CRUDOperationTO args, IActivityIOPath dstPath, IActivityIOPath p, string path, ref bool result)
 {
     if(args.Overwrite || !dst.PathExist(dstPath))
     {
         result = TransferFile(src, dst, args, path, p, result);
     }
 }
 bool DeleteUsingSftp(IActivityIOPath src)
 {
     var sftp = BuildSftpClient(src);
     try
     {
         var fromPath = ExtractFileNameFromPath(src.Path);
         if(PathIs(src) == enPathType.Directory)
         {
             sftp.DeleteDirectory(fromPath);
         }
         else
         {
             sftp.DeleteFile(fromPath);
         }
     }
     catch(Exception)
     {
         throw new Exception(string.Format("Could not delete {0}. Please check the path exists.", src.Path));
     }
     finally
     {
         sftp.Dispose();
     }
     return true;
 }
예제 #57
0
 static string GetFileNameFromEndPoint(IActivityIOOperationsEndPoint endPoint, IActivityIOPath path)
 {
     var pathSeperator = endPoint.PathSeperator();
     return path.Path.Split(pathSeperator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Last();
 }
 private static bool EnableSsl(IActivityIOPath path)
 {
     var result = path.PathType == enActivityIOPathType.FTPS || path.PathType == enActivityIOPathType.FTPES;
     return result;
 }
        /// <summary>
        /// Return the appropriate operation end point based upon the IOPath type
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static IActivityIOOperationsEndPoint CreateOperationEndPointFromIOPath(IActivityIOPath target)
        {

            lock(EndPointsLock)
            {
                // load end-points if need be... aka first load
                if(_endPoints == null)
                {
                    _endPoints = new List<Type>();
                    _referenceCheckers = new List<IActivityIOOperationsEndPoint>();

                    var type = typeof(IActivityIOOperationsEndPoint);

                    List<Type> types = typeof(IActivityIOOperationsEndPoint).Assembly.GetTypes()
                                                                             .Where(t => (type.IsAssignableFrom(t)))
                                                                             .ToList();

                    foreach(Type t in types)
                    {
                        if(t != typeof(IActivityIOOperationsEndPoint))
                        {
                            _endPoints.Add(t);
                            _referenceCheckers.Add((IActivityIOOperationsEndPoint)Activator.CreateInstance(t));
                        }
                    }
                }
            }

            // now find the right match ;)
            int pos = 0;

            while(pos < _referenceCheckers.Count && !_referenceCheckers[pos].HandlesType(target.PathType))
            {
                pos++;
            }

            // will throw exception if cannot find handling type
            IActivityIOOperationsEndPoint result =
                (IActivityIOOperationsEndPoint)Activator.CreateInstance(_endPoints[pos]);
            result.IOPath = target;


            return result;
        }
예제 #60
0
 public Stream Get(IActivityIOPath path, List <string> filesToCleanup)
 => new DoGetAction(path).ExecuteOperation();