EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Receiving Files via FTPS from MVS zOS.

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#34626
Posted: 10/07/2015 13:03:44
by Craig Boucher (Standard support level)
Joined: 03/03/2014
Posts: 8

I need to get a file from an MVS server via FTPS using SecureBlackBox. I'm able to get the file via ftp in a DOS window with the following two commands (after logging in).

cd 'PD.COCSU.FTP.STANIS'
get FC310.M093015A.AGYREC

Note: MVS uses DataSets. I don't know much about MVS, I just know its file structure is different.

When I call the Receive command in a C# console program, I get the following error:

"Unaccepted server reply (error code is 425)"

Here is the code:

Code
    class Program
    {
        static SBSimpleFTPS.TElSimpleFTPSClient Client = null;

        static void Main(string[] args)
        {
            TestFTP2();
        }

        private static void TestFTP2()
        {
            SBUtils.Unit.SetLicenseKey("<omitted>");



            Client = new TElSimpleFTPSClient();
            Client.Address = "<omitted>";
            Client.Port = 21;
            Client.PassiveMode = true;
            Client.UseSSLSessionResumption = false;

            Client.Username = "<omitted>";
            Client.Password = "<omitted>";

            Client.OnCertificateValidate += new SBSSLCommon.TSBCertificateValidateEvent(Client_OnCertificateValidate);
            Client.OnTextDataLine += new SBSimpleFTPS.TSBFTPSTextDataEvent(Client_OnTextDataLine);

            try
            {
                Client.Open();
                Client.Login();

                FileStream stream = new FileStream(@"C:\temp\M093015A.txt", FileMode.Create, FileAccess.Write);
                try
                {
                    Client.Cwd("'PD.COCSU.FTP.STANIS'");
                    Client.Receive("FC310.M093015A.AGYREC", stream);
                }
                finally
                {
                    stream.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Client.Close();
            }
        }

        static private void Client_OnCertificateValidate(object Sender, TElX509Certificate Certificate, ref bool Validate)
        {
            System.Console.WriteLine("Server certificate received");
            Validate = true; // NEVER do this. You MUST check the key validity somehow
        }

        static private void Client_OnTextDataLine(object Sender, byte[] TextLine)
        {
            string response = System.Text.UTF8Encoding.UTF8.GetString(TextLine);
            System.Console.WriteLine(response);
            TSBFTPFileInfo FileInfo = new TSBFTPFileInfo();

            try
            {
                if (Client.ExtMLSTSupported)
                {
                    TElSimpleFTPSClient.ParseMLSDEntry(response, ref FileInfo);
                }
                else
                {
                    TElSimpleFTPSClient.ParseFileListEntry(response, ref FileInfo);
                }
                System.Console.WriteLine(FileInfo.FileName);
            }
            catch (Exception)
            {
                // Couldn't parse the entry, so just write what we've received
                System.Console.WriteLine(response);
            }
        }
    }


I can open and login without getting an exception, but when I attempt to Receive the file I get the error. I've also tried a number of combinations for the filename. For example:

"'FC310.M093015A.AGYREC'"
"'PD.COCSU.FTP.STANIS.FC310.M093015A.AGYREC'"
"'PD.COCSU.FTP.STANIS(FC310.M093015A.AGYREC)'"

But still no success. I'm using version 12 of the library.

Thanks,
Craig
#34628
Posted: 10/07/2015 14:03:41
by Eugene Mayevski (EldoS Corp.)

Thank you for your report. The problem is quite interesting.

Please run the sample application which you can find in SecureBlackbox\Samples\C#\FTPSBlackbox\Desktop\Client\SimpleFTPS, and run it against the site. Please try to download the file with the sample. If this doesn't work, please grab the log from the client window (remember to remove the password and maybe an IP or host name), and post the log here for analysis.


Sincerely yours
Eugene Mayevski
#34631
Posted: 10/07/2015 17:16:47
by Craig Boucher (Standard support level)
Joined: 03/03/2014
Posts: 8

Here is the output from the Simple FTPS Client. I tried it twice. Once with Use SSL/TLS checked and once without it checked. When it was checked the download failed. When it wasn't checked the download succeeded. Here is the log from the failed download (Use SSL/TLS Checked):

<<<220-FTPSERVE IBM FTP CS V2R1 at <omitted>, 20:51:05 on 2015-10-07.
220 Connection will close if idle for more than 1440 minutes.

>>>AUTH TLS
<<<234 Security environment established - ready for negotiation

>>>USER <omitted>
<<<331 Send password please.

>>>PASS <omitted>
<<<230 <omitted> is logged on. Working directory is "<omitted>.".

>>>PBSZ 0
<<<200 Protection buffer size accepted

>>>PROT P
<<<200 Data connection protection set to private

>>>FEAT
<<<211- Extensions supported
SIZE
MDTM
AUTH TLS
PBSZ
PROT
211 End

>>>CDUP
<<<250 "" is the working directory name prefix.

>>>PWD
<<<257 "''" is working directory.

>>>CWD PD.COCSU.FTP.STANIS
<<<250 "PD.COCSU.FTP.STANIS." is the working directory name prefix.

>>>PWD
<<<257 "'PD.COCSU.FTP.STANIS.'" is working directory.

>>>TYPE I
<<<200 Representation type is Image

>>>PORT <omitted>,193,28
<<<200 Port request OK.

>>>SIZE FC310.M093015A.AGYREC
<<<550 command SIZE rejected - FC310.M093015A.AGYREC is not an HFS file

>>>RETR FC310.M093015A.AGYREC

And here it is from the successful download (Use SSL/TLS unchecked):

<<<220-FTPSERVE IBM FTP CS V2R1 at <omitted>, 20:45:52 on 2015-10-07.
220 Connection will close if idle for more than 1440 minutes.

>>>USER <omitted>
<<<331 Send password please.

>>>PASS <omitted>
<<<230 <omitted> is logged on. Working directory is "<omitted>.".

>>>FEAT
<<<211- Extensions supported
SIZE
MDTM
AUTH TLS
PBSZ
PROT
211 End

Current directory is: '<omitted>.'
>>>CDUP
<<<250 "" is the working directory name prefix.

>>>PWD
<<<257 "''" is working directory.

Current directory is: ''
>>>CWD PD.COCSU.FTP.STANIS
<<<250 "PD.COCSU.FTP.STANIS." is the working directory name prefix.

>>>PWD
<<<257 "'PD.COCSU.FTP.STANIS.'" is working directory.

>>>TYPE I
<<<200 Representation type is Image

>>>PORT <omitted>,192,201
<<<200 Port request OK.

>>>SIZE FC310.M093015A.AGYREC
<<<550 command SIZE rejected - FC310.M093015A.AGYREC is not an HFS file

>>>RETR FC310.M093015A.AGYREC
<<<125 Sending data set PD.COCSU.FTP.STANIS.FC310.M093015A.AGYREC FIXrecfm 260

<<<250 Transfer completed successfully.

In the first log file it looks like I didn't select the complete log but that is all that was there. In the Time/Event window there is an entry after the "Receiving file..." entry that says "Control channel transfer error"

Thanks,
Craig
#34638
Posted: 10/08/2015 03:42:23
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Please try to download a file is passive mode. It can be turned on in the samples connection settings window.
#34639
Posted: 10/08/2015 04:08:57
by Vsevolod Ievgiienko (EldoS Corp.)

You can also try to turn 'Use clear data channel' option on.
#34684
Posted: 10/08/2015 12:25:53
by Craig Boucher (Standard support level)
Joined: 03/03/2014
Posts: 8

Success!

I copied a few other settings from the SimpleFTPSDemo to get it working.

Code
Client.Versions = 0;
Client.Versions = (short)(Client.Versions + SBSSLConstants.Unit.sbSSL3);
Client.Versions = (short)(Client.Versions + SBSSLConstants.Unit.sbTLS1);
Client.UseSSL = true;
Client.EncryptDataChannel = true;
Client.AuthCmd = SBSimpleFTPS.Unit.acAuto;
Client.PassiveMode = true;
Client.SSLMode = SBSSLCommon.TSBSSLMode.smExplicit;
Client.TransferType = 0; //0 = ascii, 1 = binary

One last question. Although it seems to be working ok, I have some instructions that say to execute the following command after logging in:

site recfm=fb lrecl=202 blksize=20200 retpd=15

Is there a way to execute this command?

Thanks,
Craig
#34686
Posted: 10/08/2015 12:51:50
by Eugene Mayevski (EldoS Corp.)

It makes sense to try without that command and see if the resulting data is correct. If you do need this command, we have SendCmd() method to send custom commands. And if memory serves (I can't check this right now) there was a dedicated SITE command in the client as well.


Sincerely yours
Eugene Mayevski
#34688
Posted: 10/08/2015 14:05:32
by Craig Boucher (Standard support level)
Joined: 03/03/2014
Posts: 8

The SendCmd method worked.
Thanks,
Craig
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 3438 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!