Beispiel #1
0
        public IDirectory GetRootDirectory()
        {
            var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password);

            client.Connect();
            var dir = client.ListDirectory(this.RepositoryPath);

            var dir2 = client.ListDirectory("/PackageRepository/Core/0.0.1.193");

            //var sftp = new Sftp();
            return(new Directory(this.RepositoryPath, client, ""));
        }
Beispiel #2
0
        public IDirectory GetRootDirectory()
        {
            var client = new Renci.SshNet.SftpClient(this.Host, this.Port, this.UserName, this.Password);

            client.Connect();
            var dir = client.ListDirectory(this.RepositoryPath);

            var dir2 = client.ListDirectory("/PackageRepository/Core/0.0.1.193");

            //var sftp = new Sftp();
            return new Directory(this.RepositoryPath, client, "");
        }
Beispiel #3
0
        public override IEnumerable <string> GetFileListFullPath(string folder = "")
        {
            if (!String.IsNullOrEmpty(RemoteDirectory))
            {
                folder = Path.Combine(RemoteDirectory, folder);
            }

            foreach (Renci.SshNet.Sftp.SftpFile entry in _client.ListDirectory(folder))
            {
                if (!entry.IsDirectory)
                {
                    yield return(entry.FullName);
                }
            }
        }
Beispiel #4
0
 public override void list(string path, CallbackOnList callback = null)
 {
     try
     {
         if (this.connect())
         {
             this.client.ChangeDirectory(path);
             foreach (var entry in client.ListDirectory("."))
             {
                 if (callback != null)
                 {
                     if (entry.Name != "." && entry.Name != "..")
                     {
                         callback(new DirInfo()
                         {
                             name  = entry.Name,
                             full  = entry.FullName,
                             isdir = entry.IsDirectory,
                             ext   = System.IO.Path.GetExtension(entry.Name),
                             path  = path
                         });
                     }
                 }
             }
             this.disconnect();
         }
     }
     catch (Exception error) {
         if (this.log != null)
         {
             this.log(error.Message.ToString());
         }
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            Network.SelectNetwork();
            DataManager.IsServerConnected();

            List <MoveConfig> MoveConfigs = MoveConfig.MoveConfigs();

            foreach (MoveConfig MoveConfig in MoveConfigs)
            {
                //PrePostProcess.Call(MoveConfig.DirPostProcessExe);
                //Using Open Source Nuget Package SSH.NET by Renci
                using (var sftp = new Renci.SshNet.SftpClient(SFTP.host, SFTP.user, SFTP.pass))
                {
                    sftp.Connect();
                    var files = sftp.ListDirectory(MoveConfig.DirSFTP);

                    foreach (var file in files)
                    {
                        string remoteFileName = file.Name;
                        if (!file.Name.StartsWith(".") && (file.LastWriteTime.Date == DateTime.Today))
                        {
                            using (Stream file1 = File.OpenWrite(MoveConfig.DirSFTP + remoteFileName))
                            {
                                //sftp.DownloadFile(remoteDir + remoteFileName, file1);
                                break;
                            }
                        }
                    } //foreach fileInSFTP
                }     //using
            }         //foreach moveConfig
        }             //Main()
        /// <summary>
        /// List a remote directory in the console.
        /// </summary>
        public List <string> ListFiles(string remoteDirectory, ILog log)
        {
            var connectionInfo = SshClient.GetConnectionInfo(_config);

            var fileList = new List <string>();

            using (var sftp = new Renci.SshNet.SftpClient(connectionInfo))
            {
                try
                {
                    sftp.Connect();

                    var files = sftp.ListDirectory(remoteDirectory);

                    foreach (var file in files)
                    {
                        fileList.Add(file.Name);
                    }

                    sftp.Disconnect();
                }
                catch (Renci.SshNet.Common.SshConnectionException e)
                {
                    throw new RemoteConnectionException(e.Message, e);
                }
                catch (Exception e)
                {
                    log?.Error($"SftpClient.ListFiles :: Error listing files {e}");
                }
            }
            return(fileList);
        }
        private static void CheckFilesEsiti()
        {
            try
            {
                if (!CHECK_ESITI)
                {
                    return;
                }

                MoveToDownloadFolder(SFTP_DOWNLOAD_FOLDER_ESITI);

                var files = SFTPClient.ListDirectory(SFTP_DOWNLOAD_FOLDER_ESITI);
                foreach (var file in files)
                {
                    Utils.CLogger.WriteLog("analysing " + file.FullName);
                    if (!file.IsDirectory && !file.IsSymbolicLink)
                    {
                        DownloadSingleFile(file, LOCAL_DOWNLOAD_FOLDER_ESITI); //TODO aggiungi la rimozione

                        if (DELETE_XML_AFTER_DONWLOAD)
                        {
                            DeleteXmlAfterDownload(file.FullName);
                        }

                        AnalyseSingleFileEsiti(file, LOCAL_DOWNLOAD_FOLDER_ESITI);

                        if (MOVE_ESITI_ONCE_DOWNLOAD)
                        {
                            MoveEsitiToDownloadFolderBackup(file.Name);
                        }
                    }
                    else if (file.IsSymbolicLink)
                    {
                        Utils.CLogger.WriteLog("Ignoring symbolic link " + file.FullName);
                    }
                    else if (file.Name != "." && file.Name != "..")
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.CLogger.WriteLog("errore nel metodo  CheckFilesEsiti");
                Utils.CLogger.WriteLog(ex);
            }
        }
Beispiel #8
0
        public object[] list(object path)
        {
            connect();
            List <object> list = new List <object>();

            foreach (var item in _client.ListDirectory(path.ToStringOrDefault()))
            {
                list.Add(new Dictionary <string, object>
                {
                    { "name", item.Name },
                    { "fullName", item.FullName },
                    //{"type", item.Type.ToStringOrDefault()},
                    { "modified", item.LastWriteTimeUtc },
                });
            }
            return(list.ToArray());
        }