Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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


:mrgreen: Found! Sorry for trouble. Thanks so much.

Re: SCP Upload files from windows 7 to linux embedded

This could only happen if you have another definition of TransferMode enum in your project, where the Binary has value 1 (what is a value for Ascii in WinSCP .NET assembly).

Ok, I confirm that if i use the line of code:
myTransferOptions.TransferMode = TransferMode.Binary
When I stop the program with the debugger, the value of the propetry is 1 (Ascii)
If I comment the line and use the default the value is 0 (Binary).
In this way, the file are uploaded correctly.

mmmm maybe I've understand, I've notice that the line myTransferOptions.TransferMode = TransferMode.Binary set the transfer mode as ASCII! Is this possible? If I remove the line, I've got the correct value = Binary (by default I immagine). I'll try tomorrow if this fix the problem.

Just for a complete context around the issue, I've try to Download from the Linux device to the Windows PC. In this case the file is exactely the same size. Naturally I can't test if the Linux executable can run.... Also, as for my code, when I found a file on the device that have the same name, I 'move' the existing file before copy the new one. Well, even the 'renamed' file as got the bad size as well as the new file copied from the windows PC. :shock:

SCP Upload files from windows 7 to linux embedded

Hi I try to upload a file on a Linux embedded device from an application windows that use the .net assembly.
The problem is that the file goes on the device but it is corrupted. The size of the file is a bit different and on the device the file (executable) can not start (fragmentation fault). If I transfert the same file using WinSCP interface application all is ok. Probably there are some mistakes inside my code... this is the function that I call from my application code:

Public Function UploadFiles(local As String, remote As String) As Integer ' upload dei files contenuti in una directory
l.WriteLine("Upload of " + local + " to " + remote + " host: " + _ip, clsLogger.sign._INFO)
' Setup session options
Dim mySessionOptions As New SessionOptions
With mySessionOptions
.Protocol = Protocol.Scp
.HostName = _ip
.UserName = _user
.Password = _password
.SshHostKeyFingerprint = "ssh-rsa 2048 ee:f3:c1:59:4d:b4:e2:c5:da:22:3a:6e:97:a0:28:29"
.GiveUpSecurityAndAcceptAnySshHostKey = True
End With
Dim myFilePermission As New FilePermissions
myFilePermission.UserExecute = True
myFilePermission.UserRead = True
myFilePermission.UserWrite = True
myFilePermission.OtherExecute = True
myFilePermission.OtherRead = True
myFilePermission.OtherWrite = True
myFilePermission.GroupExecute = True
myFilePermission.GroupRead = True
myFilePermission.GroupWrite = True
Dim myTransferOptions As New TransferOptions()
l.WriteLine("Set TransferOptions", clsLogger.sign._INFO)
myTransferOptions.TransferMode = TransferMode.Binary
myTransferOptions.FilePermissions = myFilePermission

Using mySession As Session = New Session
' Connect
' if remote exists, rename its
If (mySession.FileExists(remote)) Then
mySession.MoveFile(remote, remote + "_old")
l.WriteLine("Rename of " + remote + " to " + remote + "_old", clsLogger.sign._INFO)
End If
' Upload files
Dim transferResult As TransferOperationResult
transferResult = mySession.PutFiles(local, remote, False, myTransferOptions)

' Throw on any error

' Print results
For Each transfer In transferResult.Transfers
l.WriteLine("Upload of " + transfer.FileName + " succeeded", clsLogger.sign._INFO)
End Using
Return 0
Catch e As Exception
Dim s As String = String.Format("Error: {0}", e)
l.WriteLine(s, clsLogger.sign._ERROR)
Return 1
End Try

End Function

Thanks for the help!