0

I am downloading files from FTP using WinSCP .NET library.

My code is

session.ExecutablePath = _appSettings["ApplicationFolderPath"] + "WinSCP.exe";
session.Open(sessionOptions);
var obj = session.ListDirectory(_appSettings["SFTP_IncomingFileFolder"]);

if (obj != null && obj.Files != null)
{
    foreach (RemoteFileInfo fileOrDo in obj.Files)
    {
        if (fileOrDo.Name == "." || fileOrDo.Name == ".." || fileOrDo.FileType == 'd' || fileOrDo.FileType == 'D')
        {
            continue;
        }

        // here I want's to check whether file is not in use  before calling  session.GetFiles(...,...).Check();
    }                    
 }

What I want's is to check file is not in use on FTP location before downloading it. Any idea what interface I should use.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93

1 Answers1

1

There's no way to test, if file is in use over FTP protocol.

Not only with WinSCP .NET assembly, but in general.


So all you can do is to try do download the file and gracefully handle any failure.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Wow. Answer from the author himself. Thanks Martin – Kamran Shahid Aug 24 '15 at 11:40
  • Martin Any idea what particular type of exception i should catch to avoid error. I am downloading multiple files in a foreach loop. I have a single catch which will break the other downloading. – Kamran Shahid Aug 28 '15 at 07:30
  • Just do not call the `.Check` method and your do not get any exception. If you want to test, use `.IsSuccess` property. See [`TransferOperationResult` Class](https://winscp.net/eng/docs/library_transferoperationresult). – Martin Prikryl Aug 28 '15 at 07:32