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)
Try
' 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
mySession.Open(mySessionOptions)
' 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
transferResult.Check()
' Print results
For Each transfer In transferResult.Transfers
l.WriteLine("Upload of " + transfer.FileName + " succeeded", clsLogger.sign._INFO)
Next
End Using
l.Dispose()
Return 0
Catch e As Exception
Dim s As String = String.Format("Error: {0}", e)
l.WriteLine(s, clsLogger.sign._ERROR)
l.Dispose()
Return 1
End Try
End Function
Thanks for the help!
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)
Try
' 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
mySession.Open(mySessionOptions)
' 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
transferResult.Check()
' Print results
For Each transfer In transferResult.Transfers
l.WriteLine("Upload of " + transfer.FileName + " succeeded", clsLogger.sign._INFO)
Next
End Using
l.Dispose()
Return 0
Catch e As Exception
Dim s As String = String.Format("Error: {0}", e)
l.WriteLine(s, clsLogger.sign._ERROR)
l.Dispose()
Return 1
End Try
End Function
Thanks for the help!