?
Solved

HOW TO IMPLEMENT SFTP using c#

Posted on 2013-01-09
4
Medium Priority
?
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 2000 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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…
Creating an OSPF network that automatically (dynamically) reroutes network traffic over other connections to prevent network downtime.
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…
Suggested Courses

752 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