Solved

HOW TO IMPLEMENT SFTP using c#

Posted on 2013-01-09
4
385 Views
Last Modified: 2013-01-11
I have the following task to implement  in a existing console application.

Can you enlighten me?

The task:

When the process is run it accepts an argument “-mailer” this will trigger the
processMailer() function. The file that is generated
in that function needs to be transferred via SFTP to
the following server info:
 
Server:                 xx.122.xxx.xxx
UID:                       azaz_group
PWD:                     xxxxxxx
 
I expect that these server details will be stored in the app.config
file so that they can be configured in the future.

How would I code this and setup in the existing app_code
I need to do this asap as the user has given me little time to implement.

Thanks,
Isaac
0
Comment
Question by:TechIsaac
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 500 total points
ID: 38760292
0
 

Author Comment

by:TechIsaac
ID: 38763284
I found SharpSSH which works nicely.

I would like to use my app_code values instead of hard code.

Is there a way to do this without a lot of string manipulation?

I am now getting the values in myString but I am using hard code.

//new code here
                string myString = ConfigurationManager.AppSettings["SftpConnectionString".ToString()];
                Sftp scp = new Sftp("00.000.000.000", "dndn_xxxxxxx");
                scp.Password = "xxxxxxxx";
                scp.Connect(00);
                scp.Put(xFerFile,xFerFile);
                scp.Close();
                tw.WriteLine(string.Format("{0:yyyy/MM/dd_hh:mm:ss:tt}", DateTime.Now) + " process completed successfully");
                tw.WriteLine(string.Format("{0:yyyy/MM/dd_hh:mm:ss:tt}", DateTime.Now) + " server transfer completed successfully");
                tw.Close();
0
 

Author Comment

by:TechIsaac
ID: 38764114
I found a solution:

string sremote = ConfigurationManager.AppSettings["SftpConnectionString".ToString()];
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(sremote);
                string user = builder.UserID;
                string pass = builder.Password;
                string server = builder.DataSource;

Isaac
0
 

Author Comment

by:TechIsaac
ID: 38767802
I've requested that this question be closed as follows:

Accepted answer: 0 points for TechIsaac's comment #a38764114

for the following reason:

The solution works in my application<br /><br />Isaac
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The article explains the protocols and technology which is involved when two computers on different TCP/IP networks communicate with each other. In the diagram, a router is used to segregate two networks. The networks are 192.168.1.0/24 and 192…
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now