当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.ListDirectory方法代码示例

本文整理汇总了C#中Renci.SshNet.SftpClient.ListDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.ListDirectory方法的具体用法?C# SftpClient.ListDirectory怎么用?C# SftpClient.ListDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SftpClient的用法示例。


在下文中一共展示了SftpClient.ListDirectory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PollHandler

        private void PollHandler()
        {
            var exchange = new Exchange(_processor.Route);
            var ipaddress = _processor.UriInformation.GetUriProperty("host");
            var username = _processor.UriInformation.GetUriProperty("username");
            var password = _processor.UriInformation.GetUriProperty("password");
            var destination = _processor.UriInformation.GetUriProperty("destination");
            var port = _processor.UriInformation.GetUriProperty<int>("port");
            var interval = _processor.UriInformation.GetUriProperty<int>("interval", 100);
            var secure = _processor.UriInformation.GetUriProperty<bool>("secure");

            do
            {
                Thread.Sleep(interval);
                try
                {
                    if (secure)
                    {
                        SftpClient sftp = null;
                        sftp = new SftpClient(ipaddress, port, username, password);
                        sftp.Connect();

                        foreach (var ftpfile in sftp.ListDirectory("."))
                        {
                            var destinationFile = Path.Combine(destination, ftpfile.Name);
                            using (var fs = new FileStream(destinationFile, FileMode.Create))
                            {
                                var data = sftp.ReadAllText(ftpfile.FullName);
                                exchange.InMessage.Body = data;

                                if (!string.IsNullOrEmpty(data))
                                {
                                    sftp.DownloadFile(ftpfile.FullName, fs);
                                }
                            }
                        }
                    }
                    else
                    {
                        ReadFtp(exchange);
                    }
                }
                catch (Exception exception)
                {
                    var msg = exception.Message;
                }
            } while (true);
        }
开发者ID:ojoadeolagabriel,项目名称:TqWorkflow-beta,代码行数:48,代码来源:FtpConsumer.cs

示例2: GetList

        public static IEnumerable<SftpFile> GetList(string host, string folder, string userName, string password)
        {

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

                var toReturn = sftp.ListDirectory(folder).ToList();

                sftp.Disconnect();

                return toReturn;
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:15,代码来源:SftpManager.cs

示例3: ListFiles

        /// <summary>
        /// Lists the files.
        /// </summary>
        /// <param name="remotePath">The remote path.</param>
        /// <param name="failRemoteNotExists">if set to <c>true</c> [fail remote not exists].</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public List<IRemoteFileInfo> ListFiles(string remotePath)
        {
            List<IRemoteFileInfo> fileList = new List<IRemoteFileInfo>();
            try
            {
                this.Log(String.Format("Connecting to Host: [{0}].", this.hostName), LogLevel.Minimal);
                using (SftpClient sftp = new SftpClient(this.hostName, this.portNumber, this.userName, this.passWord))
                {
                    sftp.Connect();
                    this.Log(String.Format("Connected to Host: [{0}].", this.hostName), LogLevel.Verbose);

                    if (!sftp.Exists(remotePath))
                    {
                        this.Log(String.Format("Remote Path Does Not Exist: [{0}].", this.hostName), LogLevel.Verbose);
                        if (this.stopOnFailure)
                            throw new Exception(String.Format("Invalid Path: [{0}]", remotePath));
                    }
                    else
                    {
                        this.Log(String.Format("Listing Files: [{0}].", remotePath), LogLevel.Minimal);
                        this.Log(String.Format("Getting Attributes: [{0}].", remotePath), LogLevel.Verbose);

                        SftpFile sftpFileInfo = sftp.Get(remotePath);
                        if (sftpFileInfo.IsDirectory)
                        {
                            this.Log(String.Format("Path is a Directory: [{0}].", remotePath), LogLevel.Verbose);
                            IEnumerable<SftpFile> dirList = sftp.ListDirectory(remotePath);
                            foreach (SftpFile sftpFile in dirList)
                                fileList.Add(this.CreateFileInfo(sftpFile));
                        }
                        else
                        {
                            this.Log(String.Format("Path is a File: [{0}].", remotePath), LogLevel.Verbose);
                            fileList.Add(this.CreateFileInfo(sftpFileInfo));
                        }
                    }
                }
                this.Log(String.Format("Disconnected from Host: [{0}].", this.hostName), LogLevel.Minimal);
            }
            catch (Exception ex)
            {
                this.Log(String.Format("Disconnected from Host: [{0}].", this.hostName), LogLevel.Minimal);
                this.ThrowException("Unable to List: ", ex);
            }
            return fileList;
        }
开发者ID:ElanHasson,项目名称:SSIS-Extensions,代码行数:53,代码来源:SFTPConnection.cs

示例4: DownloadDirectory

 private void DownloadDirectory(SftpClient client, string source, string destination)
 {
     var files = client.ListDirectory(source);
     foreach (var file in files)
     {
         if (!file.IsDirectory && !file.IsSymbolicLink)
         {
             DownloadFile(client, file, destination);
         }
         else if (file.IsSymbolicLink)
         {
             Console.WriteLine("Ignoring symbolic link {0}", file.FullName);
         }
         else if (file.Name != "." && file.Name != "..")
         {
             var dir = Directory.CreateDirectory(Path.Combine(destination, file.Name));
             DownloadDirectory(client, file.FullName, dir.FullName);
         }
     }
 }
开发者ID:dragon753,项目名称:Deployer,代码行数:20,代码来源:DeployOperation.cs

示例5: GetRemoteFilesOrFoldersList

 public static List<Renci.SshNet.Sftp.SftpFile> GetRemoteFilesOrFoldersList(string host, string user, string password, string remotePath, int type)
 {
     List<Renci.SshNet.Sftp.SftpFile> fList = new List<Renci.SshNet.Sftp.SftpFile>();
     using (SftpClient client = new SftpClient(host, user, password))
     {
         client.KeepAliveInterval = TimeSpan.FromSeconds(60);
         client.ConnectionInfo.Timeout = TimeSpan.FromMinutes(180);
         client.OperationTimeout = TimeSpan.FromMinutes(180);
         client.Connect();
         var fileList = client.ListDirectory(remotePath);
         foreach (var f in fileList)
         {
             if (f.Name != "." && f.Name != "..")
             {
                 if (type == 1)
                 {// Get folders
                     if (f.IsDirectory)
                     {
                         fList.Add(f);
                     }
                 }
                 else
                 {
                     if (f.IsRegularFile)
                     {
                         fList.Add(f);
                     }
                 }
             }
         }
     }
     return fList;
 }
开发者ID:wangn6,项目名称:rep2,代码行数:33,代码来源:SSHWrapper.cs

示例6: GetFilesRecur

 private IEnumerable<SftpFile> GetFilesRecur(SftpClient ssh, SftpFile sftpDir)
 {
     if (!sftpDir.IsDirectory)
     {
         return new[] {sftpDir};
     }
     var fl = new List<SftpFile>();
     foreach (var sftpFile in ssh.ListDirectory(sftpDir.FullName))
     {
         if (sftpFile.IsRegularFile)
         {
             fl.Add(sftpFile);
         }
         else if (sftpFile.IsDirectory && sftpFile.Name != "." && sftpFile.Name != "..")
         {
             fl.AddRange(GetFilesRecur(ssh, sftpFile));
         }
     }
     return fl;
 }
开发者ID:hmaster20,项目名称:mRemoteNC,代码行数:20,代码来源:UI.Window.SSHTransfer.cs

示例7: button1_Click

                private void button1_Click(object sender, EventArgs e)
                {
                    try
                    {
                        /*if (AllFieldsSet() == false)
                        {
                            Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg,
                                                                Language.strPleaseFillAllFields);
                            return;
                        }*/

                        lvSSHFileBrowser.Items.Clear();
                        var ssh = new SftpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
                        ssh.Connect();
                        var res = ssh.ListDirectory(txtRemoteFolderPath.Text).ToList().OrderBy(file => !file.IsDirectory).ThenBy(file => file.Name);
                        var l = new List<EXImageListViewItem>();
                        foreach (var item in res)
                        {
                            if (item.Name==".")
                            {
                                continue;
                            }
                            var imglstvitem = new EXImageListViewItem
                            {
                                MyImage =
                                    item.IsDirectory
                                        ? global::My.Resources.Resources.Folder
                                        : global::My.Resources.Resources.File,
                                MyValue = item.FullName,
                                Tag = item
                            };
                            imglstvitem.SubItems.Add(item.Name);
                            imglstvitem.SubItems.Add(item.IsDirectory ? "" : Tools.Misc.LengthToHumanReadable(item.Length));
                            l.Add(imglstvitem);
                        }
                        ssh.Disconnect();
                        lvSSHFileBrowser.Items.AddRange(l.ToArray());
                        lvSSHFileBrowser.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
开发者ID:hmaster20,项目名称:mRemoteNC,代码行数:44,代码来源:UI.Window.SSHTransfer.cs

示例8: RemoteDirectories

        /// <summary>
        /// Walks the sftp site and passes by reference all of the directories and sub directories
        /// </summary>
        /// <param name="Files"></param>
        /// <param name="Path"></param>
        /// <param name="sftp"></param>
        /// <param name="ParentDirectory"></param>
        private static void RemoteDirectories(ref List<RemoteFile> Files, string Path, SftpClient sftp, string ParentDirectory = "")
        {
            foreach (SftpFile File in sftp.ListDirectory(Path))
            {
                if (File.Name != "." && File.Name != "..")
                {
                    RemoteFile Rfile = new RemoteFile(File.Name, File.FullName, File.Length, ParentDirectory,File.IsDirectory,File.LastWriteTime,File.LastWriteTimeUtc);

                    Files.Add(Rfile);
                    if (File.IsDirectory)
                    {
                        string Path2 = Path + "/" + File.Name;
                        RemoteDirectories(ref Files, Path2, sftp, ParentDirectory + "/" + File.Name);
                    }
                }
            }
        }
开发者ID:gvl1818,项目名称:backup-retention-service,代码行数:24,代码来源:Common.cs


注:本文中的Renci.SshNet.SftpClient.ListDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。