public async Task DownloadFileAsync_ValidURL() { var hostname = "ftp://ftp.bom.gov.au/"; var filePath = "anon/gen/fwo/IDA00100.dat"; var fileName = Path.GetFileName(filePath); var client = new FTPClient(hostname); using (var fs = await client.DownloadFileAsync(filePath)) using (var outFile = File.Create(fileName)) { fs.Seek(0, SeekOrigin.Begin); await fs.CopyToAsync(outFile); } var fileInfo = new FileInfo(fileName); Assert.IsTrue(fileInfo.Exists); Assert.IsTrue(fileInfo.Length > 0); }
public async void DownloadFileAsync(string ip, string remoteFilePath, string localFilePath, string userName, string password, bool isUsePassive, CallbackContext callbackContext) { try { m_Logger.Debug($"ip:{ip},remoteFilePath:{remoteFilePath},localFilePath:{localFilePath}"); var ftpClient = new FTPClient($"ftp://{ip}"); var ftpResult = await ftpClient.DownloadFileAsync(remoteFilePath, localFilePath, userName, password, isUsePassive); callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, ftpResult)); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }