You need to be careful about transferring files from MS-Windows platform to *nix or other platforms. MS-Windows uses two bytes to indicate end-of-line while *nix, MAC and others use only one character. So if you read text files in binary mode and send that to other operating systems the receiving program has to translate the CR/LF pair to whatever the target os expects.
File transfer programs, the receiving program does the translations because the sending program may or may not know what platform it is communicating with. So, the receiving program on *nix platforms need to translate 0x0a 0x0d pair to just 0x0a and on MAC they would be translated to 0x0d (unless I have that backwards).
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
you don't do anything with files that are saved as binary files on the disk, such as executable files. Only do the translation of text files. BTW: it will do no good to transfer an executable file from MS-Windows to *nix anyway because it won't run on *nix :)
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
To be specific, i tried to send a text file across the port. The data is being received at the other end and saved to the file also. But when i open the file at the received end i observed that additional enter has been saved. After an analysis i found out that it was not exactly an enter (chr(13)) but chr(10) that appearing on the output file.
I think the scenario is still not clear. I will try to make it clear.
Today there are so many medium for file transfer like 1. Internet, 2. Pen Drive, 3. CD ...and so on.....and so there may not be much scope for file transfer through RS232. I want to do this to supplement my learning curve.
So i want to transfer an executable ( or for that matter an image file ) file byte by byte from System A to System B using RS232. Of course if System B is a *nix it won't run and that does not matter at all.
NB: Actually what i plan to implement is a cross platform file transfer utility using RS232.
Please Advise...
So does that mean your original post is wrong ? You don't want to transfer a text file but a binary file such as image or executable? Or both types ?
Again, if transfering a binary file neither the client nor the server should do anything at all with the data types -- no translation should take place. Open the files in binary mode, not text mode, like this in c++. VB has similar capability to open a file in binary mode.
// open the file for input
ifstream in("filename", ios::binary);
unsigned char* buf = 0;
// get file size
in.seekg(0, ios::end);
size_t filesize = in.tellg();
// back to beginning of the file
in.seekg(0,ios::beg);
// allocate memory for the file
buf = new unsigned char[filesize];
// read the file
in.read(buf, filesize);
// close the file
in.close();
// now send buf to the other computer over rs232 port.
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341