0 votes
by (170 points)
edited

I'm trying to send files under a folder to mainframe. I got the following error: "It is not easily possible to determine whether a file or directory exists at this server. Batch operations will not work." Why do I get this error?

Here is the code:

Ftp client = new Ftp();
client.Connect(ftpServerIP);
client.Login(ftpUserID, ftpPassword);
client.TransferType = FtpTransferType.Ascii;

client.PutFiles("c:\test\*", "//HRUNT.PER.ED.DE34.ACK.DDATA(+1)", FtpBatchTransferOptions.Recursive);
Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (73.6k points)
edited

You got the error because Batch operations are not supported with Mainframe. Only supported methods are PutFile, GetFile and GetList.

You can write your own PutFiles method for example like this:

private static void PutFiles(Ftp client, string localPath, string fileMask, string remotePath)
{
    if (string.IsNullOrEmpty(fileMask))
        fileMask = "*";

    string[] localFiles = Directory.GetFiles(localPath, fileMask);
    foreach (string localFile in localFiles)
    {
        string name = Path.GetFileName(localFile);
        string remoteFile = RemotePathCombine(remotePath, name);
        client.PutFile(localFile, remoteFile);
    }

    string[] localDirectories = Directory.GetDirectories(localPath);
    foreach (string localDirectory in localDirectories)
    {
        string name = Path.GetFileName(localDirectory);
        string remoteDirectory = RemotePathCombine(remotePath, name);
        PutFiles(client, localDirectory, fileMask, remoteDirectory);
    }
}

private static string RemotePathCombine(string remotePath, string name)
{
    return string.Format("{0}/{1}", remotePath.TrimEnd('/'), name);
}

You can use it like this:

Ftp client = new Ftp();
client.Connect(ftpServerIP);
client.Login(ftpUserID, ftpPassword);
client.TransferType = FtpTransferType.Ascii;

PutFiles(client, @"c:\test", "*.xml", "//HRUNT.PER.ED.DE34.ACK.DDATA(+1)");

Please note the method RemotePathCombine. You have to write your own implementation of it according to your Mainframe. Given implementation is for common FTP server.

...