public async Task <FtpWebResponse> GetRawResponseStream(FTPfileInfo file) { FtpWebRequest ftp = await GetRequest(_hostname + file.FullName); //Set request to download a file in binary mode ftp.Method = WebRequestMethods.Ftp.DownloadFile; ftp.UseBinary = true; return((FtpWebResponse)await ftp.GetResponseAsync()); }
public DirectoryItem(FTPfileInfo fileInfo) { InitializeComponent(); FileInfo = fileInfo; if (fileInfo.FileType == FTPfileInfo.DirectoryEntryTypes.Directory) { IconPictureBox.Image = Properties.Resources.dir; } else { IconPictureBox.Image = Properties.Resources.file; } FilenameLinkLabel.Text = fileInfo.Filename; }
public async Task FileClick(object sender, EventArgs e, FTPfileInfo file) { loadingSpinner.Visible = true; currentDirectoryForNav = currentDirectory; string ext = file.Extension.ToLower(); currentFile = file; if (ext == "jpg" || ext == "png" || ext == "jpeg" || ext == "bmp") { videoPreviewPlayer.Visible = false; textPreviewBox.Visible = false; previewPictureBox.Visible = true; using (var ftpResponse = await _client.GetRawResponseStream(file)) { using (var fileContentStream = ftpResponse.GetResponseStream()) { previewPictureBox.Visible = true; previewPictureBox.Image = Image.FromStream(fileContentStream); } } } else if (ext == "avi" || ext == "mp4" || ext == "wma" || ext == "mp3") { await _client.Download(file, Directory.GetCurrentDirectory() + "\\" + "temp." + ext, true); videoPreviewPlayer.Visible = true; textPreviewBox.Visible = false; previewPictureBox.Visible = false; videoPreviewPlayer.Warning += (Sender, Events) => { }; videoPreviewPlayer.settings.enableErrorDialogs = false; videoPreviewPlayer.URL = Directory.GetCurrentDirectory() + "\\" + "temp." + ext; videoPreviewPlayer.settings.autoStart = true; } else { videoPreviewPlayer.Visible = false; textPreviewBox.Visible = true; previewPictureBox.Visible = false; var response = await _client.GetRawResponse(file); textPreviewBox.Text = Encoding.Default.GetString(response); } loadingSpinner.Visible = false; }
public async Task <byte[]> GetRawResponse(FTPfileInfo file) { List <byte> returnValue = new List <byte>(); FtpWebRequest ftp = await GetRequest(_hostname + file.FullName); //Set request to download a file in binary mode ftp.Method = WebRequestMethods.Ftp.DownloadFile; ftp.UseBinary = true; //open request and get response stream using (FtpWebResponse response = (FtpWebResponse)await ftp.GetResponseAsync()) { using (Stream responseStream = response.GetResponseStream()) { try { Int32 read = 0; do { read = responseStream.ReadByte(); returnValue.Add((byte)read); } while (read != -1); responseStream.Close(); } catch (Exception) { throw; } responseStream.Close(); } response.Close(); } return(returnValue.ToArray()); }
//Another version taking FtpFileInfo and FileInfo public async Task <bool> Download(FTPfileInfo file, FileInfo localFI, bool PermitOverwrite) { return(await Download(file.FullName, localFI, PermitOverwrite)); }