1 and 0

BirveSifir.com: Systems, Websites, Applications.

Remote server connection by SSH using C#

leave a comment »

SSH is a secure network protocol to use remote shell services or execute commands. You can connect to a remote server by SSH on Visual Studio. To do this, you need a SSH library. My suggestion is SharpSSH.

Download DLL files from SourceForge. You should add these DLL files to your Visual Studio project:

  • DiffieHellman.dll
  • Org.Mentalis.Security.dll
  • Tamir.SharpSSH.dll

To connect to server and execute commands, code is here:

SshExec shell = new SshExec(hostIP, username);
shell.Password = password;
shell.Connect();
string output = shell.RunCommand(command);
shell.Close();

My SSH application is below. It is a simple SSH Command Prompt.

SSH Command Prompt

SSH Command Prompt

Written by 1ve0

03/18/2012 at 8:10 PM

Creating PDF, Word, Excel, Outlook and Text files using C#

with one comment

When you develop an application that needs exporting capability for several type of files, you should use some internal or external programming libraries. I will mention a few useful and free libraries for our exporting purposes.

Data Export

I don’t want to give much explanation about these libraries because you can find out easily If you want. My purpose is giving the summary (library name and basic code) about that.

Creating PDF File

Library: iTextSharp

Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream
("C:\\test.pdf", System.IO.FileMode.Create));
document.Open();
document.Add(Paragraph p1 = new Paragraph("Hello World"););
document.Close();

Creating Word File

Library: Microsoft Word 14.0 Object Library (Internal)

Application app1 = new Application();
app1.Visible = true;
_Document doc1 = app1.Documents.Add();
doc1.Words.First.InsertBefore("Hello World");
doc1.SaveAs2("C:\\test.docx");

Creating Excel File

Library: Microsoft Excel 14.0 Object Library (Internal)

_Application app = new Application();
_Workbook workbook = app.Workbooks.Add(Type.Missing);
_Worksheet worksheet = null;
app.Visible = true;
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
worksheet.Cells[1, 1] = "Hello World";
worksheet.Columns.AutoFit();
worksheet.Cells.HorizontalAlignment = Element.ALIGN_RIGHT;
workbook.SaveAs("C:\\test.xls", Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);

Creating Outlook Files (New Mail Window)

Library: Microsoft Outlook 14.0 Object Library (Internal)

Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem
(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "Hello World";
oMsg.Display();

Creating Text Files

Library: System.IO (Internal)

System.IO.File.WriteAllText("C:\test.txt", "Hello World");

Notes

To open a file, use this code:

System.Diagnostics.Process.Start("test.pdf");

Before using any library (dll), do not forget to add it as a reference (Visual Studio > Solution Explorer > Right Click on References > Add Reference):

Add Reference Windows in Visual Studio

Add Reference Window in Visual Studio

Resolution of “Cygwin installation is out of date” error when you install Moshell on Cygwin

with 2 comments

After install Cygwin by following this document (or this one as backup), the next step would be installing Moshell (Step 13 in that document). When you type “bash moshell_install” command, you see an error like this:

!!! Your cygwin installation is out of date and incompatible with the latest moshell version !!!
Please upgrade to the latest cygwin version by rerunning the setup.exe from www.cygwin.com/setup.exe

Cygwin Version Error

Cygwin Version Error

Read the rest of this entry »

Written by 1ve0

03/02/2012 at 5:56 PM

What is iperf, jperf and xjperf? How can you use them to test network performance?

with 2 comments

Iperf is a very helpful tool written in C++ to measure network bandwidth and quality. It can be used to analyze both TCP and UDP traffic.

Jperf or Xjperf (both of them are the same thing. Don’t confuse about the difference) equip Iperf with graphical interface. If you don’t like to spend your time by command line, use Jperf.

I am going to give you some information about Iperf and Jperf. First of all, the project links of these tools are here:

Read the rest of this entry »

Written by 1ve0

02/16/2012 at 3:29 PM

Which FTP client is better: FileZilla, CuteFTP or TotalCommander?

leave a comment »

Most people think that FTP speed depends on server and network speed. How about FTP client? Which FTP client should you prefer If you need high speed?

Which one is the best?

Which one is the best?

I tested three FTP clients:

  • FileZilla 3.5.3
  • CuteFTP 8.3.2
  • Total Commander 7.55

Here is test environment:

  • Operating system: Windows 7 Ultimate
  • FTP Server speed: 30 Mbps (download), 140 Mbps (upload)
  • Network speed:  32 Mbps (download), 2 Mbps (upload)

I have tried download/upload three times and calculated average. All clients have had the same conditions. The results:

FTP clients comparison

FTP clients comparison

* I used multi-part download and normal upload on CuteFTP. I used default settings on FileZilla and Total Commander.
* Passive mode was used for both download and upload (Find out more).

.

As a result:

  • Don’t use Total Commander! Upload speed of Total Commander is terrible!
  • If you like open source programs choose FileZilla.
  • If you like programs that have user-friendly interface, choose CuteFTP.

By the way, my favorite is CuteFTP!

Written by 1ve0

02/15/2012 at 9:27 PM

Follow

Get every new post delivered to your Inbox.