Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review

Antony Parakka

FTP Upload Resume Disconnection Notification

Hi Friend ,Resume is working Fine .While internet disconnected want to show message .From session.PutFiles giving no notifications

In the log I see that WinSCP reconnected successfully after the connection was restored. What do you want it to do differently?

Log attached!

The wifi connection was turned off at 13:56. However, I can see that WinSCP was attempting to reconnect with the server several times. During this, no output was given. It was only when I turned the wifi on again when the session went on to resume the transfer, and then I shut down the debugging process.

For reference, here is how my session is configured:
static void Main(string[] args)
        SessionOptions sessionOptions = new SessionOptions
            Protocol = Protocol.Sftp,
            HostName = "SERVER_URL",
            UserName = "USERNAME",
            SshPrivateKeyPath = @"C:\PuttyPrivateKey.ppk",
            SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny,
            Timeout = new TimeSpan(0, 0, 15)
        using (Session session = new Session())
            session.FileTransferProgress += SessionFileTransferProgress;
            session.SessionLogPath = @"C:\connection_loss_log_1.log";
            // Connect
            if (!session.FileExists(fileToDownload))
                Console.WriteLine("File does not exist!");
                RemoteFileInfo remoteFileInfo = session.GetFileInfo(fileToDownload);
                remoteFileSize = remoteFileInfo.Length;
                // Download files
                TransferOptions transferOptions = new TransferOptions();
                transferOptions.TransferMode = TransferMode.Binary;
                string fullDestPath = Path.Combine(destinationPath, fileToDownload);
                TransferOperationResult transferResult = session.GetFiles(fileToDownload, fullDestPath, false, transferOptions);
                // Throw on any error
    catch (SessionLocalException sle)
        Console.WriteLine("SessionLocalException " + sle.Message);
    catch (SessionRemoteException sre)
        Console.WriteLine("SessionRemoteException " + sre.Message);
    catch (Exception ex)
        Console.WriteLine("Error in ProcessEdi() while downloading EDI files via FTP: Message:" + ex.Message + "Stacktrace: " + ex.StackTrace);
static void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e)
    long currentSize = (long)(remoteFileSize * e.FileProgress);
    Console.WriteLine("Progress: " + currentSize +" of " + remoteFileSize);
    Console.WriteLine("OVerallProgress: " + e.OverallProgress);

Re: How to detect internet connection loss during transfer?

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

How to detect internet connection loss during transfer?

Hey everyone, I'm fairly new to WinSCP in .NET. I have been using SSH.NET so far, but I can't make it handle internet connection losses properly. And since WinSCP offers resuming file transfer after disconnection, I just HAD to try it :)

Currently I am testing a situation where a user would download 1 file only, while they are conencted through a VPN. Turning off the VPN doesn't seem to faze WinSCP as the download resumes after a while without issue. Yet turning all internet connections off (Wifi in this case) just makes the transfer stay on a lull, with no exceptions thrown or any prompt whatsoever.

My question is, is there a way where WinSCP can react to a complete internet connection loss? Or at least a disconnection from the server?

I have had a look (and tested) both Session.GetFiles() and Session.GetFileToDirectory().
GetFiles does have the Check() method to throw any errors, but it does not seem to do anything.

Any feedback is appreciated. Thanks in advance! :)

Edit: I use the SFTP protocol, if it helps.