.Net ConsoleApp FluentFtp create a Logfile - c#

I put the FluentFtp nuget package in my project and am trying to write some information into a log file, unfortunately without success!
I don't understand how the code is included.
It doesn't find FtpTrace in the current context, even though I imported the FluentFtp Nuget package.
FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"));
FtpTrace.LogUserName = false; // hide FTP user names
FtpTrace.LogPassword = false; // hide FTP passwords
FtpTrace.LogIP = false; // hide FTP server IP addresses
Link to site with the code (Github)
Can someone help me please?
thx

Related

Open and/or download a file from a server location to the client computer (C#, Blazor Server App)

I have a file located inside a folder on my server: F:\Data\Attachments\a.pdf.
I'm using Blazor server app with asp.net 5.0 and C#. Up to now, the user that uses the application can upload this file. This file is correctly saved inside my server folder.
I can open the file with the powershell on my computer on which the Blazor Server App is running thanks to \\ip_server\Data\Attachments\a.pdf and I checked the permissions of the folder on the server.
I want to create a button that consent to download the file on the client machine (so, notify the browser and open the save dialog to choose the destination) or something similar because I tried everything without success.
I also tried to open the file using a link <a href="file:////ip_server/Data/Attachments/a.pdf" >link</a>.
When my file was located inside the project folder, I had no problem. So, how can I solve this issue? Is there something that I'm missing?
If you need any other information, please ask.
Thanks in advance.

Put file somewhere it can be attached to an email in Xamarin targeting Android API 29

I am supporting an Android app written in Xamarin which has a feature where the user can email logs and SQLite db file to a support email address. It does this by zipping up the files and then copying the ZIP to the public Downloads folder, then attaching them to an email.
It uses the Download folder so that other apps have permission to access the files, and I can see them if I connect to my PC with a USB cable.
This has worked fine until now - to deploy an update to the Play Store I now have to target API 29 and this no longer works. The function to move the ZIP file to the Download folder fails.
I use the following method to get the path to the new file in the download folder:
var path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);
although VS is showing this method as obsolete:"deprecated"
When I try and move the ZIP file to it, I get
System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/logs.zip" is denied.
I have added
android:requestLegacyExternalStorage="true"
to my manifest, which has made no difference at all.
If I switch back to targeting API 28, all works fine.
Is there anywhere at all I could put the file to allow the user's default email app to read it as an attachment?
If you have requested for the read and write runtime permissions. Check the suggestions is the link below. Android 9.+ API 29: /storage/emulated/0/Pictures/myPic.png open failed: EACCES (Permission Denied)
And use the code below to replace the deprecated method.
var path = Path.Combine(GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);

Azure WebService can't find one of my assemblies but it's there based on Azure Console

I am very new to Azure and WebServices so please bear with me here. Basically, I have a WebService that references 3 different dlls SOCreate.dll, EOTCBase.dll, EOTC_InBuffer.dll, not standard .NET dlls but rather dlls from other projects I have. After I published a WebService on Azure successfully, I am calling my WebService which calls a method in EOTCBase.dll. The method in EOTCBase.dll tries to load an EOTC_InBuffer.dll assembly like so:
Assembly dbAssembly = Assembly.LoadFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\EOTC_InBuffer.dll");
but that call fails with an error The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
When I check what files I have on Azure I can see my WebService and a bin folder:
then I go inside the bin folder and can see all 3 dlls in there:
I guess that means that all 3 dlls are published on Azure and are available in bin folder. I tried to google for something similar but wasn't able to find a similar scenario. Could somebody please maybe point what's wrong here or maybe reference a link to some reading materials? Thank you.
P.S. It almost looks like that all those 3 dlls in the same bin folder based on Azure Console output but in fact some of them not in there actually.
UPDATE
I mean open kudu on the portal, and manually add the mydll folder as in my screenshot. The specific path of the .dll file is D:\home\site\wwwroot\mydll\a.dll. In this way, if the operation is successful, you don't need to worry about the temporary folder. Copy all the .dll files that will be used to the mydll folder.
PRIVIOUS
You can use dynamic load function to use your .dll file. If this is successful locally, and unsuccessful after deployment, then the problem should be the Azure cloud environment.
#region Dynamically load .dll
object obj=null;
byte[] filesByte;
Assembly assembly;
Type type;
MethodInfo timerInitial;
MethodInfo timerDispose;
#endregion
private void LoadDll()
{
try
{
filesByte = File.ReadAllBytes(Path.GetDirectoryName(Application.ExecutablePath) + "//EOTC_InBuffer.dll");
assembly = Assembly.Load(filesByte);
type = assembly.GetType("EOTC_InBuffer.dll");
obj = System.Activator.CreateInstance(type);
timerStart = tp.GetMethod("TimerStart");
timerStop = tp.GetMethod("TimerStop");
if (timerStart != null)
{
timerStart.Invoke(obj, null);
}
}
catch(Exception)
{
}
}
You are successful in running locally, but deploying to Azure will fail. This problem cannot be dealt with, because we cannot register the .dll in the Azure environment, nor can we read and load these .dll files in the bin folder through code.
I have replied to this question in another post before, and also tried to use the code to deal with this problem but all failed, I hope it will help you.

Selective FTP download using .NET

I have an ftp build site where new builds will be updated.
It will create a new folder named "Build XXXXX" in a specific ftp location for every new build. I need to download the build from a location inside "Build XXXXX"directory (eg. Builds\Build XXXXX\German\iso\German.iso). Here I can't predict number XXXXX.
I'm planning of writing a .NET application to automatically monitor the ftp location for any new Build XXXXX folder and if it is present, the application should download the file at the specified location (ie \German\iso).
How can I do that. Is there any API available for selectively downloading files.
Also, is there any tools already available to do this?
You can simply use the methods of the WebClient class for this.
I don't think there will be any tool tailor made for your requirement. But if you have the client library, you can make one yourself.

How to present credentials in order to open file?

How do I specify the username and password in order for my program to open
a file for reading?
The program that needs to access the file is running from an account that
does not have read access to the folder the file is in.
Program is written in C# and .NET 2, running under XP and file is on a Windows Server 2003 machine.
You want to impersonate a user who does have the rights to access the file.
I recommend using a class like this - http://www.codeproject.com/KB/cs/zetaimpersonator.aspx. It hides all the nasty implementation of doing impersonation.
using (new Impersonator("myUsername", "myDomainname", "myPassword"))
{
string fileText = File.ReadAllText("c:\test.txt");
Console.WriteLine(fileText);
}
I have used the Nuget package NuGet Gallery | Simple Impersonation Library 1.1.0 but there are others; search on Impersonation for the others.
Example usage using the interactive login to work with file structures:
using (Impersonation.LogonUser("{domain}",
"{UserName}",
"{Password}",
LogonType.Interactive))
{
var directory = #"\\MyCorpServer.net\alpha\cars";
Assert.IsTrue(Directory.Exists(directory));
}
James' answer below was before Nuget and before he would later have the most downloaded package on Nuget. Ironic eh?
You can impersonate a user who has the necessary rights. There is an article on MSDN that describes how to do this.

Categories

Resources