Problem with GetFiles

0 votes
asked Aug 3, 2011 by hyau (230 points)
edited Nov 2, 2012

I am using version 3.0.3793.0 of the Rebex Ftp library and I am having problem with the multiple download method GetFiles(). I notice the library did a listing of the remote directory but never download any files.

My code is like this:

client.GetFiles("/home/TESTACC/DOWNLOAD/VRCLNT.*", "C:\\", FtpBatchTransferOptions.Default, FtpActionOnExistingFiles.OverwriteAll);

The log coming from the Rebex library is:

220-QTCP at UNISEN05.
220 Connection will close if idle more than 5 minutes.
USER TESTACC
331 Enter password.
PASS ********
230 TESTACC logged on.
FEAT
211-Feature listing follows:
 AUTH TLS
 CCC
 PBSZ
 PROT
211 End of feature listing.
TYPE I
200 Representation type is binary IMAGE.
SIZE .
500 Subcommand SIZE not valid.
MDTM .
500 Subcommand MDTM not valid.
PWD
257 "TESTACC" is current library.
CWD /home/TESTACC/DOWNLOAD
250-NAMEFMT set to 1.
250 "/home/TESTACC/DOWNLOAD" is current directory.
HierarchyRetrievalStarted
PWD
257 "/home/TESTACC/DOWNLOAD" is current directory.
CWD /home/TESTACC/DOWNLOAD
250 "/home/TESTACC/DOWNLOAD" is current directory.
CWD /home/TESTACC/DOWNLOAD
250 "/home/TESTACC/DOWNLOAD" is current directory.
TYPE A
200 Representation type is ASCII nonprint.
PORT 10,87,3,147,230,217
200 PORT subcommand request successful.
LIST /home/TESTACC/DOWNLOAD
125 List started.
250 List completed.
HierarchyRetrieved
Applies to: Rebex FTP/SSL

5 Answers

0 votes
answered Nov 2, 2012 by Tomas Knopp (58,890 points)
edited Nov 2, 2012
 
Best answer

The cause for the non-working GetFiles() operation was that Rebex client expected the datetime format to be in MM/DD/YY format whereas the server you used returned it as YY/MM/DD.

To get around this problem we have added property As400ListingDateFormat, which can be used like this to set the expected datetime listing format to YY/MM/DD:

client.Settings.As400ListingDateFormat = "YMD"; // all combinations (MDY, DMY, DYM, etc.) are possible
client.GetFiles("/home/TESTACC/DOWNLOAD/VRCLNT.*", "C:\\", FtpBatchTransferOptions.Default, FtpActionOnExistingFiles.OverwriteAll);

The property is available since release 2012 R3.

0 votes
answered Aug 4, 2011 by Lukas Matyska (55,650 points)
edited Aug 4, 2011

Please note the FtpBatchTransferOptions.Default is non-recursive, so your code should download all "VRCLNT.*" files from the "/home/TESTACC/DOWNLOAD" directory. If this is what you want please post here the result of the LIST command, which can be done like this:

string [] list = client.GetRawList("/home/TESTACC/DOWNLOAD");
File.WriteAllLines("c:\\list.output.txt", list);
0 votes
answered Aug 4, 2011 by hyau (230 points)
edited Jan 12, 2012

I have ran the code and the output is listed below.

PHNACCMSTR    1655 06/01/31 16:30:41 *STMF    /home/TESTACC/DOWNLOAD/VR00CLNT.A306PHN9
PHNACCMSTR    1160 06/03/09 11:21:18 *STMF    /home/TESTACC/DOWNLOAD/VR00CLNT.C086PHN9
commented Aug 5, 2011 by Lukas Matyska (55,650 points)
edited Aug 5, 2011

Thank you for the output. The problem is the server returns full names, but we expect file names only. I fixed this problem and sent you a mail with the link to the current build. Please give it a try and let me know if you are able to GetFiles successfully.

0 votes
answered Aug 5, 2011 by hyau (230 points)
edited Aug 8, 2011

Use the newer version and it still failed with the following exception:

It is not easily possible to determine whether a file or directory exists at this server. Batch operations will not work.

Rebex Log

220 Connection will close if idle more than 5 minutes.
USER TESTACC
331 Enter password.
PASS ********
230 TESTACC logged on.
FEAT
211-Feature listing follows:
 AUTH TLS
 CCC
 PBSZ
 PROT
211 End of feature listing.
TYPE I
200 Representation type is binary IMAGE.
SIZE .
500 Subcommand SIZE not valid.
MDTM .
500 Subcommand MDTM not valid.
PWD
257 "PHNEFTACC" is current library.
CWD /home/TESTACC/DOWNLOAD
250-NAMEFMT set to 1.
250 "/home/TESTACC/DOWNLOAD" is current directory.
CWD PHNEFTACC
550-Specified directory does not exist or cannot be accessed.
550 Working directory not changed.
HierarchyRetrievalStarted
PWD
257 "/home/TESTACC/DOWNLOAD" is current directory.
CWD /home/TESTACC/DOWNLOAD
250 "/home/TESTACC/DOWNLOAD" is current directory.
CWD /home/TESTACC/DOWNLOAD
250 "/home/TESTACC/DOWNLOAD" is current directory.
TYPE A
200 Representation type is ASCII nonprint.
PORT 10,87,3,147,52,187
200 PORT subcommand request successful.
LIST /home/TESTACC/DOWNLOAD
125 List started.
250 List completed.
HierarchyRetrieved
FileProcessingStarted
TYPE I
200 Representation type is binary IMAGE.
PWD
257 "/home/TESTACC/DOWNLOAD" is current directory.
CWD /home/TESTACC/DOWNLOAD/VR00CLNT.A306PHN9
550-Specified directory does not exist or cannot be accessed.
550 Working directory not changed.
FileProcessingFailed
0 votes
answered Aug 8, 2011 by Lukas Matyska (55,650 points)
edited Aug 8, 2011

Batch operation such as the GetFiles method is a very complex function and in the present form it needs some features to be supported by the server. For example to determine whether a specified item (file/directory) exists on the remote host and which properties has.

Unfortunately your server doesn't support MLST nor MDTM nor SIZE command. We are sorry, but you cannot use the GetFiles method against your FTP server.

Still, you can write your simple version of GetFiles method as follows:

private static void GetFiles(
    Ftp client, string sourceDirectory, string targetDirectory, string fileMask)
{
    fileMask = Regex.Escape(fileMask).Replace("\\?", ".").Replace("\\*", ".*");
    Regex filter = new Regex(fileMask);

    FtpList list = client.GetList(sourceDirectory);
    foreach (FtpItem item in list)
    {
        if (!item.IsFile)
            continue;

        string name = Path.GetFileName(item.Name);
        if (!filter.IsMatch(name))
            continue;

        string source = string.Format("{0}/{1}", sourceDirectory, name);
        string target = Path.Combine(targetDirectory, name);

        client.GetFile(source, target);
    }
}

And use it like this:

GetFiles("/home/TESTACC/DOWNLOAD", "C:\\", "VRCLNT.*");

If you need a hint, how to write recursive transfers, please don't hesitate to ask.

...