File upload using SSL fails

Please post here if you have problems in using Wing FTP Server.

File upload using SSL fails

Postby jalcroft » Wed Sep 08, 2021 12:41 pm

Hi all

We have a number of WingFTP servers, on Windows, and we have a routine which transfers files via FTP. This is done using .NET C# application, and the code is below:

FtpWebRequest loFTPWeb;
try
{
//string folder from file name
string lsAbsFile = Path.GetFileName(psFileName);
if (psFolder != "")
//file needs to go into a subfolder on the ftp server
lsAbsFile = psFolder + lsAbsFile;

loFTPWeb = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}", psServer + ":" + psPort, lsAbsFile))) as FtpWebRequest;
loFTPWeb.Method = WebRequestMethods.Ftp.UploadFile;
loFTPWeb.UseBinary = true;
loFTPWeb.UsePassive = true;
loFTPWeb.KeepAlive = true;
loFTPWeb.Credentials = new NetworkCredential(psUsername, AISCrypto.DecryptString(psPassword));
loFTPWeb.ConnectionGroupName = "group";
loFTPWeb.EnableSsl = true;

using (FileStream loStream = File.OpenRead(psFileName))
{
byte[] buffer = new byte[loStream.Length];
loStream.Read(buffer, 0, buffer.Length);
loStream.Close();
Stream loSendSteam = loFTPWeb.GetRequestStream();
loSendSteam.Write(buffer, 0, buffer.Length);
loSendSteam.Close();
loSendSteam.Flush();
}

This is working fine with our older system (6.3.3 or older), but our latest system is on version 6.4.9 or 6.6.1 it fails. The reported error is SYSTEM ERROR, which I know isn't helpful. If I set the EnableSSL option to False, it works to all FTP Servers.

I have gone through all settings on both a working server and none working server. I can't see any differences that stand out as relating to SSL connections. There is a valid certificate on these servers.

I am not allowed access to the firewall, and I am thinking this is more of a firewall port 22 issue. Am I right?

Anything else that I can look at?

Many thanks.

James
jalcroft
 
4
 
Wed Sep 08, 2021 12:30 pm

Re: File upload using SSL fails

Postby FTP » Wed Sep 08, 2021 3:27 pm

OK, could you find any error message under WingFTP's domain logs?
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: File upload using SSL fails

Postby jalcroft » Wed Sep 08, 2021 4:18 pm

Hi. If I'm looking at the correct logs, which i think I am, I see this.

[02] Wed, 08 Sep 2021 12:17:05 (0001304) Connected from 52.186.86.221 (local address 10.4.1.228, port 21)
[04] Wed, 08 Sep 2021 12:17:05 (0001304) 220 Wing FTP Server ready...
[03] Wed, 08 Sep 2021 12:17:05 (0001304) AUTH TLS
[04] Wed, 08 Sep 2021 12:17:05 (0001304) 234 AUTH command OK. Initializing TLS connection.
[02] Wed, 08 Sep 2021 12:17:05 (0001304) Closed session, disconnected from 52.186.86.221
[02] Wed, 08 Sep 2021 12:17:20 (0001303) Failed to exchange the keys.
[02] Wed, 08 Sep 2021 12:17:20 (0001303) Closed session, disconnected from 222.186.30.76


Looks like the certificate hasn't been applied correctly to WingFtp.

James
jalcroft
 
4
 
Wed Sep 08, 2021 12:30 pm

Re: File upload using SSL fails

Postby FTP » Wed Sep 08, 2021 4:44 pm

OK, maybe it is caused by the self-signed SSL cert (or invalid SSL cert), so you can skip the certificate validation by the following code:

Code: Select all
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: File upload using SSL fails

Postby jalcroft » Wed Sep 08, 2021 4:52 pm

Hi. It isn't a self-signed cert. It is the same certificate on all our other FTP servers.

I'm assuming this command is to be run in the admin console. Do I need to replace parameter with values as I get an error:
some error in [string "ServicePointManager.ServerCertificateValidationCallback += (sen..."]: 1: '=' expected near '+'!
jalcroft
 
4
 
Wed Sep 08, 2021 12:30 pm

Re: File upload using SSL fails

Postby FTP » Wed Sep 08, 2021 4:57 pm

The above code is C# code, you just need to add it before your C# code.
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: File upload using SSL fails

Postby jalcroft » Thu Sep 09, 2021 12:37 pm

Hi
I think the information from logs I provided yesterday were incorrect. We have someone constantly trying to hack onto port 22 - now disabled.
I have just tried to send another file, and the logs show nothing more helpful than the SYSTEM ERROR that I initial reproted:

[02] Thu, 09 Sep 2021 08:34:49 (0000052) Connected from 87.127.25.221 (local address 10.4.1.228, port 21)
[04] Thu, 09 Sep 2021 08:34:49 (0000052) 220 Wing FTP Server ready...
[03] Thu, 09 Sep 2021 08:34:49 (0000052) AUTH TLS
[04] Thu, 09 Sep 2021 08:34:49 (0000052) 234 AUTH command OK. Initializing TLS connection.
[02] Thu, 09 Sep 2021 08:34:49 (0000052) Closed session, disconnected from 87.127.25.221

James
jalcroft
 
4
 
Wed Sep 08, 2021 12:30 pm

Re: File upload using SSL fails

Postby FTP » Fri Sep 10, 2021 12:48 am

Already told you, just skip the certificate validation by adding one line code:

Code: Select all
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

FtpWebRequest loFTPWeb;
try
{
//string folder from file name
string lsAbsFile = Path.GetFileName(psFileName);
if (psFolder != "")
//file needs to go into a subfolder on the ftp server
lsAbsFile = psFolder + lsAbsFile;

loFTPWeb = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}", psServer + ":" + psPort, lsAbsFile))) as FtpWebRequest;
loFTPWeb.Method = WebRequestMethods.Ftp.UploadFile;
loFTPWeb.UseBinary = true;
loFTPWeb.UsePassive = true;
loFTPWeb.KeepAlive = true;
loFTPWeb.Credentials = new NetworkCredential(psUsername, AISCrypto.DecryptString(psPassword));
loFTPWeb.ConnectionGroupName = "group";
loFTPWeb.EnableSsl = true;

using (FileStream loStream = File.OpenRead(psFileName))
{
byte[] buffer = new byte[loStream.Length];
loStream.Read(buffer, 0, buffer.Length);
loStream.Close();
Stream loSendSteam = loFTPWeb.GetRequestStream();
loSendSteam.Write(buffer, 0, buffer.Length);
loSendSteam.Close();
loSendSteam.Flush();
}
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests