Topic "SCP Upload files from windows 7 to linux embedded"

Author Message
[View user's profile]

Joined: 2015-02-24
Posts: 8
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!
[View user's profile]

Joined: 2015-02-24
Posts: 8
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. Shocked
[View user's profile]

Joined: 2015-02-24
Posts: 8
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.
[View user's profile]

Joined: 2015-02-24
Posts: 8
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.
Very Happy
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24759
Location: Prague, Czechia
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).
[View user's profile]

Joined: 2015-02-24
Posts: 8
Mr. Green Found! Sorry for trouble. Thanks so much.

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License