1

I've exhausted all my resources at this point, so I come asking for help.

I have a client that has given me a username and password to their ftp site. However, to access it on the web uses https://ftps.sitename.com

To access on FileZilla, I can either use ftps:// or sftp://

My problem is that I have no idea what I need to do to access it inside my program.

Right now I have this code:

var ftpFilePath = @"ftp://ftps.sitename.com/file.txt";
var request = (FtpWebRequest)WebRequest.Create(ftpFilePath);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredentials(username, pass);
// enable SSL?

var response = (FtpWebResponse)request.GetResponse();
// Other code

It's currently failing on GetResponse with the error that it cannot connect to the remote server. If I use "ftps://ftps.sitename.com" then I get an error complaining about the prefix.

This is my first time dealing with this type of problem, and I must have missed something small. Any help is greatly appreciated.

EDIT:

I ended up using the WinSCP package and followed this tutorial: https://winscp.net/eng/docs/library_session_getfiles

Two problem I ran into is that I don't have a ssh key, so I am temporarily setting

GiveUpSecurityAndAcceptAnySshHostKey = true

And then I ran into a small issue of making sure the process that runs VS had access to the path I was attempting to write the file to.

ELepolt
  • 373
  • 2
  • 4
  • 16
  • http://blogs.msdn.com/b/adarshk/archive/2005/04/22/410925.aspx might help. – Ron Beyer Aug 12 '15 at 18:17
  • @RonBeyer: I found a similar answer to that yesterday, but no help. Off the top of my head I don't remember what error I was receiving. – ELepolt Aug 13 '15 at 14:54
  • @MartinPrikryl: It looks like when I do that it's really just trying to connect to ftp://ftps.sitename.com/ and when I've tried that it's giving me an error that I'm unable to connect to the server. – ELepolt Aug 13 '15 at 14:55
  • You wrote that you ended up using WinSCP with `GiveUpSecurityAndAcceptAnySshHostKey`. But that's for SFTP, not FTPS. So isn't the real problem that you were supposed to use SFTP, not FTPS? There's no SFTP support in .NET framework. – Martin Prikryl Aug 14 '15 at 06:06
  • To be honest, this is the first time I've ever dealt with transferring to/from anything ftp related, so I'm really not sure exactly what my problem was. Which is probably why I had such a hard time answering it. Through FileZilla I was able to use sftp or ftps along with the site name. – ELepolt Aug 14 '15 at 16:05

2 Answers2

1

There are two types of FTPS: implicit and explicit. They are not compatible.

Implicit FTPS uses port 990 by default and just assumes everything is SSL/TLS from the get-go, whereas explicit FTPS connects in plain FTP to port 21 and then switches to SSL/TLS when the AUTH command is sent.

FileZilla uses the prefix 'ftps' for implicit FTPS and 'ftpes' for explicit FTPS, so if it works in FileZilla with ftps:// then that indicates that the server supports implicit FTPS. .NET probably interprets ftps:// as explicit FTP as that is the 'modern' form for FTPS (implicit FTPS is legacy).

So this may be your problem. You may be trying to connect to a legacy (implicit) FTPS server on port 990 using client-side code (in .NET) that assumes 'modern' FTPS on port 21.

There may not be a trivial solution to this since I think WebRequest supports neither implicit FTPS nor SFTP. Unless you can get the server admins to add support for explicit FTPS then you may have to use a dedicated FTPS client, such as the one that I'm one of the developers for, edtFTPnet/PRO, which supports implicit FTPS.

I hope that helps.

HansA
  • 1,375
  • 2
  • 11
  • 19
0

on your project, set target framework to 4.5.2 or above

set the security protocol to use tls1.2:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  • 1
    This isn't a question about TLS. Hard-coding the TLS version isn't ideal either. In *this* case though it won't help at all - one needs to set the `EnableSSL` property to use FTPS. Once that's set, the OS's default encryption will be used in any .NET runtime above 4.6, ie TLS1.2 or better – Panagiotis Kanavos Feb 25 '19 at 12:17
  • ok, i should have specified that in my case the FTPS is using explicit FTPS. had the same problem and tried to do the prefix "trick", no luck. (i had enableSSL property set), so i did some research and: - changed the .NET to latest version: no luck - changed the tls version (forcing it): it worked. so i guess if i'm using a net above 4,6 it should work without the need of hardcoding the tls version? – Raúl Díaz Feb 25 '19 at 17:36