コード例 #1
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var host           = Host.Get(context);
            var port           = Port.Get(context);
            var userName       = UserName.Get(context);
            var password       = Password.Get(context);
            var remoteFullPath = RemoteFullPath.Get(context);
            var localPath      = LocalPath.Get(context);

            ///////////////////////////
            // Add execution logic HERE
            ///////////////////////////
            ///

            using (var sftp = new SftpClient(host, port, userName, password))
            {
                sftp.Connect();

                using (var file = File.OpenWrite(Path.Combine(localPath, remoteFullPath.Split("/".ToCharArray())[remoteFullPath.Split("/".ToCharArray()).Length - 1])))
                {
                    sftp.DownloadFile(remoteFullPath, file);
                }

                sftp.Disconnect();
            }

            // Outputs
            return((ctx) => {
            });
        }
コード例 #2
0
ファイル: Download.cs プロジェクト: 4al14me011/SFTP_Uipath
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(SFTPScope.ParentContainerPropertyTag);

            // Inputs
            var remoteFullPath = RemoteFullPath.Get(context);
            var localDirectory = LocalDirectory.Get(context);

            ///////////////////////////
            // Add execution logic HERE
            ///////////////////////////
            SftpClient sftp_session = objectContainer.Get <SftpClient>();

            //sftp_session.Connect();
            using (var file = File.OpenWrite(Path.Combine(@localDirectory, Path.GetFileName(remoteFullPath))))
            {
                sftp_session.DownloadFile(@remoteFullPath, file);
            }
            //sftp_session.Disconnect();


            // Outputs
            return((ctx) => {
            });
        }