.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

FtpWebRequest + sftp

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :ASP.Net

Hi All,

I need a program that would download all csv files from an sftp location. I've the sftp host IP, user name, password and port details of the sftp location. I am able to login through Filezilla. But as I need to login programmatically, so that I can get a list of all files in the folder.

When the code works fine for a ftp request, it doesn't for an sftp request. Given below is my code to connect to the ftp uri.

FtpWebRequest FtpRequest = (FtpWebRequest)WebRequest.Create("ftp://myuri");
FtpRequest.Credentials = new NetworkCredential("username", "password");
FtpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

My system admin says that there is no uri that could be given for sftp sites at all. Now, how can I go about this? Is there any third party tool available for this? If yes, suggest me some good ones.

Thanks in advance.





View Complete Post

More Related Resource Links

Service to monitor SFTP location


Hi there,

I want to develop a service (may be Web / WCF / Windows) to monitor a SFTP location for excel files. As soon as any excel file arrives, service should be able to move it to some location and initiate another process.

My queries are:

1. Can we monitor SFTP using services? If not, what are the other ways to monitor.

2. Which service (Web / WCF / Windows) should I use? What could be the challenges?

Any help is highly appreciated. Thanks

FtpWebRequest - how to upload two files on FTP server using only one connection?

Hi I am using FtpWebRequest with option KeepAlive = true. When I upload first file I create ftp request object: FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create(""); I set KeepAlive = true and I do upload file. When I want upload second file I have to create new FtpWebRequest object using new URI FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create("");   I set KeepAlive = true and I do upload file. The problem is that I have to create new FtpWebRequest so I create new connection to FTP server (I have checked using netstat -b command that my application uses another port number for second file). How can I upload two files (or more) using only on FTP connection/session? Regards  

Unable to use FTPWebRequest over SSL

Hi   I have been trying to connect to a FTP server using SSL. I have followed the example on MSDN - ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/P_System_Net_FtpWebRequest_EnableSsl.htm However I keep getting an exceptions when then "request.GetResponse" method is called. The exceptions is "WebException" and message is "The underlying connection was closed: The server committed a protocol violation"   Does anybody have any working example to connect to a FTP server over SSL? Thanks for your help.

FtpWebRequest.EnableSSL error

I'm getting a "The remote certificate is invalid according to the validation procedure" Authentication Exception message with the following code:   ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(MyCertValidationCb); var request = (FtpWebRequest)WebRequest.Create(new Uri(myUri)); request.EnableSsl = true; request.Method = WebRequestMethods.Ftp.UploadFile; request.BeginGetRequestStream(EndGetStreamCallback, _state); public static bool MyCertValidationCb(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors) { return false; } if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch) { Zone z; z = Zone.CreateFromUrl(((FtpWebRequest)sender).RequestUri.ToString()); if (z.SecurityZone == SecurityZone.Intranet || z.SecurityZone == SecurityZone.MyComputer) { return true; } return false; } return false; } The ftp server is filezilla. FTP over SSL is enabled, and Allow explicit FTP over TLS is also enabled. I've generated a certificate.crt file. Connected to the ftp location using filezilla client, and checked "Always trust

How do I connect to SFTP without password from c#

Can anyone help me to connect to the ftp site from c# with following details. for example         I have private key located in c:\IT\abc.ppk         username: abcd         Server type:SFTP         there is no password         Logon Type: Interactive I can connect using above from filezilla. How do I connect from c#. Please give me some idea if anyone knows. Thanks JunaedBD    

FTPWebRequest to VMS system


Hello and how is it? I believe this error is due to the directory listing set to MS-DOS, but I want to validate this first. when I call the getRequestStream() I recieve this WebException error: 550-Failed to set default directory to DISK$SMSUSER1^:^[MyUser^]. 550 invalid directory.


If this is due to the directory listing style not set to VMS can I change this with in the FTPWebRequest class? Thanks Smile




FTPWebRequest Issue


I have written the following code that successful ftps a file to the proper location as long as the file exists on the server itself....

However, I need the code to pull the file contents from the client computer, not the server. 

Here is the code:

        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
            if (Page.IsValid)
                    FtpWebRequest ftpr = 
                        (FtpWebRequest)FtpWebRequest.Create(@"ftp://" + ConfigurationManager.AppSettings["remoteHost"] + "/" + 
                                                                        ConfigurationManager.AppSettings["remotePath"] + "/" + 

                    ftpr.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["remoteUser"].ToString(), 

Copy file from SFTP


Hi all,
I need to create an application which copies files from SFTP and paste them on my computer.

Can anyone please tell me how can I do this. I do not want to use any library of other providers like j* or others.


Class for SFTP in .Net Framework 4



Is there any SFTP class available in .NET framework 4.0? 

Thank you,


FtpWebRequest GetResponse Error on Linux Server but work on Windows Server



I have a big problem when I tried to list directory from FTP Server on linux but using the FtpWebRequest.

An error occurs at the GetResponse() method but the same code work fine on Windows Server (IIS).

The error is :

The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.InvokeRequestCallback(Object obj)
   at System.Net.CommandStream.Abort(Exception e)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetResponse()
   at FilePostman.Program.GetListFtp(NodeItem item)
   at FilePostman.Program.ReceiveFtp(NodeItem item)
   at FilePostman.Program.Main(String[] args)

The information that I use when run time like this:

Windows 2003

  Host :

  path : fmd/inbox

  uri :

  User : administrator

  Password : *******


SFTP Free component developed in C#





i want to upload/download files from SSH server using SFTP. can anyone tell me Is there any free component available for SFTP?






FtpWebRequest - Access to IBM AS/400 FTP Server - 501 Character (/) not allowed in object name.

Hello everybody

I'm trying to communicate with an AS/400 FTP Server. As a first try I just execute the WebRequestMethods.Ftp.ListDirectory method, which translates to the NLST FTP command. Doing the same accessing a Microsoft FTP Server or a UNIX FTP Server works fin.

This is the code to get the listing:

Dim Uri As System.Uri = New System.Uri(listUrl)
Dim listRequest As FtpWebRequest = CType(WebRequest.Create(Uri), FtpWebRequest)
listRequest.Credentials = New System.Net.NetworkCredential(User, Password)listRequest.Method = WebRequestMethods.Ftp.ListDirectory
listRequest.KeepAlive =
listRequest.UseBinary =


I want to do SFTP using c#. how it can be done ??

class for sftp in .net 2.0

Is there any class available for SFTP in .net framework 2.0? If there is any provision availble in other frameworks
kindly mention in the answer?

how to write a SFTP client ,SFTP server in .net 2.0?is there any option to write it in vc++?

How to change the MS-FTP sample from FTP to SFTP




The FTPSample below from Microsoft is very helpfull to get my application to send a file via FTP to a server.

Now our company is moving from FTP to SFTP and I need to update my application to use not only FTP but also SFTP.


I don't want to use any (paid) 3rd party applications.


I did find the FtpWebRequest.EnableSsl Property but there must be something more than just setting this property to true.


Can someone explain me how to change or what to add to the current MS-FTPSample in VB so that I can also send via SFTP?


Thank you.




This is the MS sample for FTP which I need to get on SFTP:

Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)

Dim requestStream



Can anyone give me some direction on how to create a SSIS Package that opens up SFTP/SSH (Ftp) and downloads files to SQL Server/HardDrive.

Now a regular FTP Task will now work if I am correct?

SSH/SFTP Communications in C#

I'm looking to get started implementing a SFTP handler in my application (.net 2.0) and so far I'm just not finding what I'm looking for. Seems like all the SSH/SFTP code and libraries out there are for the Linux crowd.

Can anyone point me in the right direction? Am I going to be making calls to a command-line SSH app, or is this something that's going to be doable with reasonable effort?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend