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


I use .NET c#, uploading larger files (MB and GB) and FileProgress always report only 0 and 1.

session.FileTransferProgress += (s, e) =>
        if (fileTransferState.Canceled)
            e.Cancel = true;
        fileTransferState.BitesWritten = (long)(fileTransferState.StreamLength * e.FileProgress);
session.PutFile(readStream, remotePath);

That was the problem. It was only a 5KB file that transferred fast. Once I sent a larger file, the progress did show fractions. Thanks.

Re: FileProgress only shows 0 or 1

How large are the files? How long does it take to transfer one file?

FileProgress only shows 0 or 1

I am trying to get a progress bar working with Access VBA. The file transfers correctly, but the FileProgress only shows 0 or 1.

The following code is my class module:
Option Compare Database
Option Explicit
Private WithEvents MySession As WinSCPnet.Session
Private Sub MySession_FileTransferProgress(ByVal sender, ByVal e As WinSCPnet.FileTransferProgressEventArgs)
  Dim progress As Double
  progress = e.FileProgress * 100#
  Debug.Print progress, e.CPS
End Sub
Public Sub OpenConnection(Protocol As WinSCPnet.Protocol, HostName As String, UserName As String, Password As String, SshHostKeyFingerprint As String)
  Set MySession = New WinSCPnet.Session
  Dim MySessionOptions As New WinSCPnet.SessionOptions
  With MySessionOptions
    .Protocol = Protocol
    .HostName = HostName
    .UserName = UserName
    .Password = Password
    .SshHostKeyFingerprint = SshHostKeyFingerprint
  End With
  MySession.Open MySessionOptions
End Sub
Public Sub UploadFile(LocalFileName As String, RemoteFileName As String)
  Dim MyTransferOptions As New WinSCPnet.TransferOptions
  Dim MyTransferResult As WinSCPnet.TransferOperationResult
  MyTransferOptions.TransferMode = TransferMode_Binary
  Set MyTransferResult = MySession.PutFiles(LocalFileName, RemoteFileName, False, MyTransferOptions)
End Sub
Public Sub CloseConnection()
End Sub

I am calling like this:
 Dim sftp As New clsWinSCP
  sftp.OpenConnection Protocol_Sftp, RemoteServer(2), RemoteUser(2), RemotePassword(2), "ssh-rsa 1024 c69mpwnBX+y3BE0t5zywJHyJOtx/xwzb+JmFHwTPIig="
  sftp.UploadFile LocalFilePath & "\" & fileName$, RemoteFilePath(2)

The debug output is:
 0             0 

 0             0
 100           0
 100           0
 100           0
 100           0

Any ideas?