Exemplo n.º 1
0
        /// <summary>
        /// Get all file names in a directory
        /// </summary>
        /// <returns>
        /// Array of file names as strings
        /// </returns>
        public async Task <string[]> DirectoryListAsync(string fileNamePrefix, string folderName)
        {
            return(await Task.Run(
                       () =>
            {
                List <string> fileNames = new List <string>();
                using (Sftp client = new Sftp())
                {
                    client.Connect(SftpUri);
                    client.Login(Username, Password);
                    client.ChangeDirectory(folderName);
                    SftpItemCollection list = client.GetList();
                    foreach (SftpItem item in list)
                    {
                        if (item.Name.ToUpper().StartsWith(fileNamePrefix.ToUpper()))
                        {
                            fileNames.Add(item.Name);
                        }
                    }
                }

                return fileNames.ToArray();
            }
                       ));
        }
Exemplo n.º 2
0
        private void lvServer_DoubleClick(object sender, EventArgs e)
        {
            string dirName = ((ListItemInfo)lvServer.SelectedItems[0].Tag).FullPath;

            try
            {
                _ftp.ChangeDirectory(dirName);
                UpdateServerList(dirName);
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Upload a file to the server
 /// </summary>
 /// Name of the file to Create
 /// <param name="fileName">
 /// </param>
 /// <param name="stream">
 /// File content as stream data
 /// </param>
 /// <returns>
 /// Async Task Wrapper
 /// </returns>
 public async Task UploadFileAsync(string fileName, Stream stream, string folderName)
 {
     await Task.Run(
         () =>
     {
         using (Sftp client = new Sftp())
         {
             client.Connect(SftpUri);
             client.Login(Username, Password);
             client.ChangeDirectory(folderName);
             client.PutFile(stream, fileName);
         }
     }
         );
 }
Exemplo n.º 4
0
        public ReturnBox UploadFile(string src, string dir, string filename)
        {
            ReturnBox r = new ReturnBox();

            if (Connected)
            {
                try
                {
                    using (var fs = new FileStream(src, FileMode.Open))
                    {
                        Sftp.BufferSize = 4 * 1024; // bypass Payload error large files
                        Sftp.ChangeDirectory(dir);
                        Sftp.UploadFile(fs, filename, true);
                    }
                    r.Success = true;
                }
                catch (Exception ex)
                {
                    r.Error = ex.Message;
                }
            }
            return(r);
        }