Search code examples
c#.netftpftpwebrequestzos

FTP over SSL to z/OS to List Directory Files


I'm trying to connect to a z/OS FTP server to download files but first I need to list them in order to find out which is the most recent. The server has an unknown certificate I have to trust and I've used the code below which included a warning about not using in production

ServicePointManager.ServerCertificateValidationCallback =
    delegate (
        object s,
        X509Certificate cert, 
        X509Chain chain, 
        SslPolicyErrors sslPolErrors) { return true; };

I'm having a really hard time listing the files in the directory I'm after. It seems z/OS is a real pain. I basically need to connect to the FTP server over SSL which I've managed to do but changing working directory has proven to be difficult.

string ftpPath = @"ftp://192.168.1.1/'THE.DIRECTORY.I.NEED.TO.CONNECT.TO'";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(remoteFtpPath);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential("username","password");
request.KeepAlive = request.UsePassive = request.EnableSsl = true;

Am I connecting to the working directory I need with my ftpPath string? If not, what's the proper way of changing working directory? The only way I've seen to do it after some google research is to include it in my ftpPath string.

The error I get doing it this way is given 550 No data sets found...


Solution

  • The URL for the ListDirectory method should in general end with a slash.

    Without a slash, results tend to be uncertain, largely depending on the FTP server implementation.