0 votes
by (120 points)
edited

Carriage Return characters in text files get corrupted/removed on ftp download

Hello,

I am using both Rebex FTP/TLS and SFTP to download files from a UNIX server (either in normal or sftp mode).

In both schemes, I am downloading text files using the TransferType.Binary property.

However, all the downloaded files have the Carriage Return character removed.

If I check the text file on Unix and the one I downloaded via Rebex, using a diff tool like WinMerge it shows that I have differences in Carriage Returns between the two files, other than that they are exactly the same.

How can I have my files downloaded EXACTLY as they exist in the remote UNIX system?

Thank you P.

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (58.9k points)
edited

Hello,

in BINARY mode, the file is transmitted "as is" by both Rebex FTP/SSL and SFTP components, i.e. without any modifications. The Binary mode is also the default mode.

So please try to download the file from your servers with the following code:

client.Connect("server");
client.Login("user", "pass");
client.Download("remoteFile", @"C:\MyData\");

where client is instance of either Ftp or Sftp class.

Does it work for you now? If the above code creates a file which is different from the remote file on your server, please send us log of communication created according to this article and the piece of code you are using to download.

by (120 points)
edited

Hi, I am using client.GetFile() instead of client.Download and client.PutFile() instead of client.Upload().

Am I doing anything wrong ?

by (120 points)
edited

I tried again my code and I always get the file without any carriage returns on download with client.GetFile(). If, however, I change the TransferType.Ascii, it works.

I don't understand. Binary should cover my needs in the first place, shouldn't it ?

by (58.9k points)
edited

We are really not modifying the transfered files in Binary mode with none of the methods (GetFile, PutFile, Upload, Download, etc).

It is perfectly ok to use GetFile and PutFile methods, which are meant for uploading / downloading single files.

When you get strange downloaded file by Rebex in Binary mode with GetFile / Download method, it is the exact copy of what was at the server. How do you create the files at the server?

by (58.9k points)
edited

So are you talking about Rebex SFTP or FTP/SSL?

In binary mode we handle the files "as is". So binary mode is meant for binary data.

Whereas the ASCII mode is primarily meant for textual files. Are you trying to transfer text or binary data?

by (120 points)
edited

I have created a method which creates an FTP/TLS or SFTP connection according to caller (method) requirements.

Currently, I am testing against a server that supports normal FTP (not SFTP).

I cannot know beforehand what files I am going to download, i.e. text or binary files. I noticed this issue while instructing the program to download text files created on a unix server on user request.

Is it not safer to always use Binary mode for any kind of files, i.e. text or binary?

Otherwise, I must somehow set beforehand the transfer type to use in my transfer, correct?

by (58.9k points)
edited

Well you could handle this problem by having a config file for your program which would contain two set of file extenstions - one set for files which will be handled as text files (i.e. with line ending conversions) and the other for files which will be handled as binary files ("as is").

You would then decide in your program by the config file + extension of the actual transmitted file.

...