Home Forums .NET libraries Xceed SFTP/FTP for .NET How do I free resources from failed download

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21177 |

    I am using the FtpClient to receive a file from a remote server. Some times when the file is being received, the connect may get timed out or disconnected for other reasons. With my file only partially downloaded, I cannot seem to do anything with it (delete it, move it, rename it, etc.) I get a message that the file is being used by another process.

     It appears as though my application has some sort of lock on the file. How can I make sure that all FtpClient resources are free of any hold on this file? While receiving the file I am catching any exception, so that seems like a good place to free any hold on the file by the FtpClient instance.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Chris (had 3257 views)

    User (Old forums)
    Member
    Post count: 23064

    FtpClient closes all its streams, so this should not be a problem. 

    Can  you provide a code snippet on how you do things, so we can try to reproduce the issue, and investigate it further?

     

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 2053 views)

    User (Old forums)
    Member
    Post count: 23064

    I am still having the problem on ocassion. I’ll include some sample code of what I am doing, but I’ll add a little more explaination first.

     My program (a Windows Service) will connect to a remote server, and start to download a file to a local server. During the download the connect may be dropped for any number of reasons (such as command execution timed out). The download is wrapped in a try-catch block which will notify me of a problem then return to the calling code. The partially downloaded file can not be deleted because the operating system thinks another application is using the file. If I stop the service and then restart it, the lock on the file is freed. It is a .NET C# application but the no other part of the application accesses the file unless the download was successfull. That is why I feel it is the Xceed FtpClient that still has a lock on the file.

    ——-Sample————– 

    FtpClient

    ftp = new FtpClient();

    http://ftp.Timeout = 90;

    http://ftp.KeepAliveInterval = 120;

    http://ftp.PassiveTransfer =

    true;

    http://ftp.RepresentationType =

    RepresentationType.Binary;

    try{

    http://ftp.ReceiveFile(fileinfo[filenum].Name, zipDest);

    }

    catch (FtpException fe)

    {

    receiveFailed =

    true;

    ftpMsg = fe.Message;

    }

    if (receiveFailed)

    {

    ftp =

    new FtpClient();  // This was added to see if reinitialization would free the lock.

    return (“Error: Lost connection, reason = “ + ftpMsg);

    }

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Chris (had 1712 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    It would be a good idea to add

            if( client.Connected )
              client.Disconnect();

    as the first statement of your if (receiveFailed) block.

    Let us know if this suggestion eliminates the file lock.

     

     

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Ghislain (had 227 views)

    User (Old forums)
    Member
    Post count: 23064

    Will do!

    It may take a little bit before I know if the problem continues as the failures occur randomly.

     Thanks!

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Chris (had 2832 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.