0 votes

I am attempting to download files and log them individually while that happens. Here is my code:

List<FtpItem> items = ftp.GetList(Globals.FtpFolder);
foreach (FtpItem item in items)
{
    Log("Downloading " + item.Name + "...");
    ftp.Download(item.Name, Globals.Localfolder + item.Name);
}

When I run this, it successfully logs the first file in the ftp folder, but it is not downloaded. No other ftp files are logged or downloaded.
Then the program finishes successfully without error.

What am I missing?

by (350 points)

1 Answer

0 votes

Please wrap your code in try...catch block. It seems to me you are getting an exception - maybe some local path problem or no permissions to save the file?

by (301k points)
Tried that. The catch returns:
Limilabs.FTP.Client.FtpResponseException: File not found.

I've verified in debug mode that the folder (Globals.FtpFolder) exists and that the files exist in the folder.

items = 47
item.Name = commonltr.css (as it should for the first file)

but the Download command throws the exception
Can you try downloading using Ftp.Download method that takes FtpItem as a parameter.
I have done this now and have the same issue.

This code:
    try
    {
        List<FtpItem> items = ftp.GetList(Globals.SelectedProfileStagingFolder);
        foreach (FtpItem item in items)
        {
            Log(" - Downloading " + item.Name + "...");
            DownloadFtpFile(item.Name);
        }
    }
    catch (Exception ex)
    {
        //Log(ex.ToString());
        File.AppendAllText(Globals.DefaultErrorLogPath, "\n");
        File.AppendAllText(Globals.DefaultErrorLogPath, ex.ToString());
        MessageBox.Show(ex.ToString());
        Console.Write(ex.ToString());
    }


calls this code:

    private void DownloadFtpFile(string f)
    {
        ...
            
    }




ftp.Download(f, Globals.UserDocumentsTempStgFolder + f)  reports the current file name is "commonltr.css" as expected.

However it still throws the exception File Not Found.
You are still using string overload. Use Download method that thtakes entire FtpItem class as parameter. Please also note that this error is raised by your server, not the component.
Sorry, I'm not understanding the usage of the FtpItem class to formulate your suggestion.
Use Ftp.Download(FtpItem item, string local) instead of Ftp.Download(string remote, string local):

List<FtpItem> items = ftp.GetList(Globals.FtpFolder);
foreach (FtpItem item in items)
{
    Log("Downloading " + item.Name + "...");
    ftp.Download(item, Pah.Combime(Globals.Localfolder, item.Name));
}

Also please turn on logging:
https://www.limilabs.com/blog/logging-in-ftp-dll
...