login about faq

Using Chilkat.Sftp dll, I am writing .csv file in the Linux Server.

I am using WriteFileBytes Function to write the file.

Function WriteFileBytes(ByVal handle As String, ByVal byteData As Byte()) As Boolean

Just noticed that, this function writes space characters along with the existing column values. Our database application which imports data from the csv file throws exception. After debugging, we found that there is additional space characters on the file.

How to fix this ? Do i need to use WriteFileText or any other WriteByte Method or WriteBinaryFile to overcome this error ?

asked Sep 18 '14 at 23:29

chilldll's gravatar image


The FTP protocol has some options to upload files in text mode (convert crlf -> lf) and you probably have those options set in Chilkat. The SFTP protocol does not have such an option. Most likely the source file you are uploading has CRLF bytes for line-ending. You will need to remove them yourself before you upload to an SFTP server.


answered Sep 20 '14 at 14:26

Gert's gravatar image

Gert ♦

The WriteFileBytes method sends the exact bytes to the SFTP server with no modifications. It does not examine that bytes that you pass to it.

Please think about this for a moment: Does it seem likely that for some insane reason WriteFileBytes will attempt to analyze the bytes that are passed to it, somehow recognize that it is CSV, insert SPACE characters are regular points within the CSV, and then send it?


answered Sep 19 '14 at 09:08

chilkat's gravatar image

chilkat ♦♦

Issue is, .csv file written by Chilkat.Sftp WriteByte Method has CRLF at the end of everyline. When i do it through FTP, i have LF in the end of every line.alt text


answered Sep 19 '14 at 15:57

chilldll's gravatar image


When you call sftp.OpenFile, examine the value of the last argument (createDisposition) that you are passing. Refer to the online reference documentation for information about it.

Also, given that you must have code that opens the .csv, and reads its contents into memory, check to make sure the LF to CRLF conversion did not happen in the code prior to calling WriteFileBytes


answered Sep 22 '14 at 09:24

chilkat's gravatar image

chilkat ♦♦

From the Sample code : http://www.example-code.com/vbdotnet/sftp_readTextFile.asp I am able to read the file in the SFTP server. In the sample code, they have mentioned the bytes for each row to read. In my scenario, I have to use End of File. How to alter the code to read end of the line. This will help to solve the issue.

(Sep 22 '14 at 11:58) chilldll

Thank you Chilkat. Issue is solved. When the .csv file is uploaded, I am validating the .csv file by recreating a Temp .csv file in the Temp folder.

I recreate it by reading the data from .csv file and ensure about CR LF or LF.

Below syntax, validates the .csv file and append LF in the end of row. No Carriage Return.

This works for either FTP or SFTP.

Dim strPath As String = String.Empty
strPath = "C:\Windows\Temp\" & _file_Name


Dim reader As System.IO.StreamReader = New System.IO.StreamReader(System.IO.File.OpenRead(.txtFileName.Text.Trim()))

Dim listA As New List(Of String)()

If System.IO.File.Exists(strPath) Then
End If

Dim sw As New System.IO.StreamWriter(strPath)
Dim s As String = String.Empty

While reader.Peek() >= 0
Dim line As String = reader.ReadLine()
       Dim values As String() = line.Split(";"c)
       s = s + line + Chr(10)
End While


Catch ex As Exception
End Try

answered Sep 24 '14 at 09:59

chilldll's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Sep 18 '14 at 23:29

Seen: 1,351 times

Last updated: Sep 24 '14 at 09:59

powered by OSQA