Solved

HOW TO IMPLEMENT SFTP using c#

Posted on 2013-01-09
4
397 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
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…

735 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