how to program to integrate with filezilla in C#.[sftp] - c#

I would like to integrate FileZilla with my application written in C#.
please someone show me sample code or web site that shows sample code.
although i found article on web, and that article was saying
"application is integrated with FileZilla is so slow".
but i don't know if i can stand that late or not.
so i would like to challenge.

To support FTP/SFTP or any other protocol in C# you can do it in 3 ways:
1. NEW APP PROCESS - Start an app that does the FTP communication in separate process, and be able to control what file to download, where to save it and to tell the app to terminate when download is finished. This way, you can use FileZilla only if it lets you pass certain parameters in command line, like the URI of the resource you want to transfer through FTP/SFTP, and the path where the file should be saved to. And as I can see HERE this could work.
To start the process and pass it command line arguments in C# you would do something like this:
static void StartNewProcess(string app, string args)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = app; //full app path
startInfo.Arguments = args; //command line arguments
startInfo.CreateNoWindow = true; //dont create app window
startInfo.WindowStyle = ProcessWindowStyle.Hidden; //hide app from taskbar
Process.Start(startInfo);
}
Now you can execute FileZila app, pass it args containing file URL and let it do its job... But you cant know how long will it take to download the file, when the download is ended, do you need to log in to get it...
2. EXISTING CLASS LIBRARY - Include a Class Library that is written by someone else, that does the job. This way you are in TOTAL control of the process. And as many other suggested, this would be a perfect way for you. Many answers here contain good class libraries that you can use and be happy with the results.
3. HOME-MADE CLASS LIBRARY - Open RFC 959, read it all and write your code... (Now 2. sounds better, doesn't it? :D)

Filezilla is a GUI FTP client, you can't use it to "script" SFTP operations (it only accepts a very limited set of command line arguments).
You must seek a third party C# component or write one yourself (not recommended) to do the job.

To support FTP or SFTP from your C# application, you could use an external library like the one from Chilkat http://www.chilkatsoft.com/ftp-2-dotnet.asp. I use it and it works great!
In theory, you could also implement the FTP protocoll using socket connections by yourself, but you should save yourself that trouble -> don't reinvent the wheel...

I recommend using SharpSSH, if you need to send files via SSH/SFTP in your application.

Related

Start Node.js server from a C# Application

A requirement has arisen that I need to start a Node.js server from a C# application, this is as simple as running a server.js script within the Node.js console. However, I'm not entirely certain how exactly to achieve that.
Here's what I've looked into so far:
In the Node.js installation, there's a file called C:\Program Files (x86)\nodejs\nodevars.bat, this is the command prompt window for Node.js. To start the server, I could possibly be using the following steps:
Execute the nodevars.bat file.
SendKeys to the new process console window to start the server.
This approach feels a bit fragile. There's no guarantee that the target user will have their Node.js installation in the same place, also sending keys to a process may not be an ideal solution.
Another method could be:
Write a batch file that executes nodevars.bat.
Execute the batch file from the C# application.
This seems like a better approach. However, the only problem here is that the nodevars.bat opens in a new console window.
So to the question(s), is there a way I can start a node.js server script using functionality built into the node.js installation? Perhaps sending arguments to the node.exe?
If it is to serve multiple users, i.e. as a server, then you can use the os-service package, and install a Windows service. You can then start and stop the service using the standard API.
If you are to start the server as a "single purpose" server, i.e. to serve only the current user, then os-service is the wrong approach. (Typically when using this approach you will specify a unique port for the service to use, which will only be used by your application).
To start a batch file or other Console application, from C#, without showing a console window, use the standard method, but be sure to specify:
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false; // This is important
psi.CreateNoWindow = true; // This is what hides the command window.
psi.FileName = #"c:\Path\to\your\batchfile.cmd";
psi.Arguments = #"-any -arguments -go Here"; // Probably you will pass the port number here
using(var process = Process.Start(psi)){
// Do something with process if you want.
}
There are a few different ones but I recommend the os-service package.

Printing any file type

I'm creating a service that will monitor a specific folder and print any file that is put in this folder. I'm having difficulties with the various file types that could be sent to the folder to be printed.
My first attempt is with Microsoft Office files. What I'm trying to do is start the office to print the file. It's more like a catch, I'm not really using a library or anything like it.
So far this approach would work, but when no Office application has ever started on the machine the Office asks for the user initials. So, in this case my application would just not work, since I'm doing this programatically.
ProcessStartInfo info = new ProcessStartInfo(myDocumentsPath);
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Right now I am trying with Microsoft Office files, but I will apply the same approach for other types as well.
There is anyway to get around the Initials required by the first Office run?
Or any better approach to my problem?
Any help is appreciated, thanks in advance.
There's not really anything that you can do; for the application which will print each type of file that you're going to support, you need to make sure the application is configured correctly.
This means that for office (since it is run as an out-of-process COM server) you should run it under the account that is performing the printing so you can enter the initials and won't be prompted for it when the server attempts to print it.
The same for every other application (assuming the application is executed to print it), it needs to be run as the account the process is going to be run under and configured correctly.
Use Winternals's regmon registry activity monitor to figure out where Office stores the initials in the windows registry, then write these keys prior to printing.

Using the php engine inside a c# application

I would like to give my users the ability to configure some php script to interact with my applycation.
I would like to give the user a Memo. The user writes some code with a php syntax, then press execute. The php engine executes the code, so I can print a result.
For example I would like to write something like:
PHPassembly = Assembly.LoadFrom("php5ts.dll");
ExecutePHPScript(PHPassembly,StringContainingAScript);
ResultVar=GetPHPVar(PHPassembly,"ResultVar");
I don't have a web server. I don't have an internet connection. Only a local application for windows.
I have tryed to load the php5ts.dll, but the compiler says that I need an assembly manifest.
Someone knows how to interact with php?
You need 2 files (from php-5.3.5-Win32-VC9-x86) php-win.exe and php5ts.dll
Than just place those 2 files in you executable directory and run:
string code = "echo 'test';";
System.Diagnostics.Process ProcessObj = new System.Diagnostics.Process();
ProcessObj.StartInfo.FileName = "php-win.exe";
ProcessObj.StartInfo.Arguments = String.Format("-r \"{0}\"", code);
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
ProcessObj.StartInfo.RedirectStandardOutput = true;
ProcessObj.Start();
ProcessObj.WaitForExit();
string Result = ProcessObj.StandardOutput.ReadToEnd();
MessageBox.Show(Result);
You can try hosting the php runtime locally. There are preconfigured packages for that, with PHP + Apache, like xampp and WampServer. This way, you can call it via HTTP requests to localhost (such an approach is discussed here).
With a bit of configuration,you could execute your code against php running on the command line.
See php.net for more info
in search of something similar myself I found this question.
maybe port and include code from http://ph7.symisc.net/index.html if you don't need too fancy php stuff?

Run a DOS command in .NET

I have a set of commands like:
C:
cd Project
testproj.exe
My system gets these commands one by one from a remote system.
I need to execute each command in cmd.exe on receiving the command from the remote system. How to execute these using .NET?
I also need to return the result of testproj.exe to the remote machine. How to take the result after running command?
Process.Start cmd.exe, and hook StandardIn, StandardOut, and StandardError. Then, when a command comes in, just write it to StandardIn and read StandardOut/Error for the return. The whole thing shouldn't be more than 15 LOC.
That being said, just installing the Telnet Server would probably be easier - as it sounds like that's what you're essentially replicating....
var process = System.Diagnostics.Process.Start( "testproj.exe" );
process.WaitForExit();
var result = process.ExitCode;
This won't really honor things like "C:" or "CD path". Instead you'd want to create a batch file in a temporary folder then call the batch file.
Take a look at System.Diagnostics.Process. You can redirect stdout/stderr somewhere to get the output.
The C: and cd Project operations can be done inside the lanching application using the Directory class using the SetCurrentDirectory method.
Then just use the Process class to launch the testproj.exe executable.
Instead of trying to support all the commands of DOS, just have a small subset implemented which will guarantee nothing can go wrong. Like Don't allow DELETE, RD, FORMAT etc.
So, basically you would only have a subset of DOS commands. Once you have the command set, you can code for those specific commands using a extension mechanisms or as pluggable modules.
This will also helps you safe guard your machine from malicious attacks and worst to happen is there could be data sent out but from machine, the data / system can never be harmed.
UPDATE: The implementaion of specific commands is left to you. You could use .NET API or have System.Diagnostics.Process

Best way to run a tool from ASP.Net page

I have a developer tool that I want to run from an internal site. It scans source code of a project and stores the information in a DB. I want user to be able to go to the site, chose their project, and hit run.
I don't want the code to be uploaded to the site because the projects can be large. I want to be able to run my assembly locally on their machine. Is there an easy way to do this?
EDIT: I should note, for the time being, this needs to be accomplished in VS2005.
EDIT 2: I am looking for similar functionality to TrendMicro's Housecall. I want the scan to run locally, but the result to be displayed in the web page
You could use a ClickOnce project (winform/wpf) - essentially a regular client app, deployed via a web-server. At the client, it can do whatever it needs. VS2005/VS2008 have this (for winform/wpf) as "Publish" - and results in a ".application" file that is recognised by the browser (or at least, some browsers ;-p).
You might be able to do the same with Silverlight, but that has a stricter sandbox, etc. It would also need to ask the web-server to do all the db work on its behalf.
I want to be able to run my assembly
locally on their machine
Sounds like you want them to download the tool and run it from their local machine, does that work for you?
Any code can scan files given the location and permissions. For a website to open an exe on a different machine and permit that to run and get access to the files contained on the web server would require a horrifically low level of security that would mean the entire system is practically completely open to attack. If your system is completely behind a firewall and hence protected from outside intererance then you want to look more at the permissions and less at the code.
To run an exe on a machine try following notepad example, though you may have to use a specified directory as well
ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(ExitHandlerToKillProcess);
p.StartInfo = psi;
p.Start();
and when done dont forget to kill the Process. Alternately use javascript. Either way watch the security permissions and remember the risks of doing this.
I would probably write some sort of command line tool or service that does the processing and extraction of project data. Then I would use a page to update/register projects that the web server and the command line tool both have common access to. then at specified times either manually or via cron or similar mechanisms extract the data to your database. once you have this, you just use the website to display last extraction times and the extracted data.
if the projects/end users are on a different subnet etc, then you will need the end users to run the tool and then have it post the data into the database.

Categories

Resources