Exemplo n.º 1
0
        public void CheckDownloadFile()
        {
            string       ftp_uri = $"{Config.Server_Address}/zip_file.zip";
            const string path    = "downloaded_zip_file.zip";

            try
            {
                using (var ftp = new FileTransferProtocol(ftp_uri, path, Config.Username, Config.Password))
                {
                    if (ftp.RequestFileDownload())
                    {
                        Assert.That(ftp.RequestStatusCode == FtpStatusCode.OpeningData || ftp.RequestStatusCode == FtpStatusCode.DataAlreadyOpen);
                        ftp.DownloadFile();
                        Assert.That(ftp.RequestStatusCode == FtpStatusCode.ClosingData);
                        Assert.That(File.Exists(path));
                    }
                    else
                    {
                        throw new ArgumentException("Retrieved stream is invalid.");
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception is WebException)
                {
                    Assert.Fail(exception.Message);
                }
            }
        }
Exemplo n.º 2
0
 public void Execute(string ftpUri, string path = null, string username = null, string password = null)
 {
     Console.WriteLine("File download beginning...");
     using (var ftp = new FileTransferProtocol(ftpUri, path, username, password))
     {
         try
         {
             if (!ftp.RequestFileDownload())
             {
                 Console.Write(ftp.RequestStatus);
                 return;
             }
             Console.Write(ftp.RequestStatus);
             if (File.Exists(path))
             {
                 Console.WriteLine("A file with the same name already exists. Overwrite file? [y/n]");
                 string userResponse = Console.ReadLine() ?? string.Empty;
                 if (userResponse.ToUpper() != "Y")
                 {
                     Console.WriteLine("File download aborted.");
                     return;
                 }
             }
             ftp.DownloadFile();
             Console.Write(ftp.RequestStatus);
         }
         catch (Exception exception)
         {
             Console.WriteLine($"{ftpUri} download error -> {exception.Message}");
         }
     }
 }