File transfer over UART

Hello All,
I am trying to share .txt, .csv file over uart using c code. I want to share .txt/.csv file from BBB to LPC2478, but now i am sending it PC over uart and looking results on TeraTerm.

On TeraTerm, content of txt file is printed but i want to share whole file to PC over uart.
Please share your outputs.

Regards,
Avinash

C code is given below-

#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(void) {
    int file;
    char buf[1024];  // Adjust the buffer size as needed
    size_t nbytes;
    ssize_t bytes_written;
    struct termios oldtio, newtio;

    // Open the serial port
    if ((file = open("/dev/ttyS1", O_RDWR | O_NOCTTY)) < 0) {
        printf("UART: Failed to open the file.\n");
        return;
    }

    // Save the current serial settings
    tcgetattr(file, &oldtio);

    // Clear the structure for new port settings
    memset(&newtio,0, sizeof(newtio));

    // Set new serial port settings (adjust as needed)
    newtio.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
    newtio.c_iflag = IGNPAR | ICRNL;

    // Apply new settings immediately
    tcflush(file, TCIFLUSH);
    tcsetattr(file, TCSANOW, &newtio);

    // Open the file in binary mode
    FILE *fileToSend = fopen("/home/debian/Downloads/123.csv", "rb");
    if (!fileToSend) {
        perror("Error opening file");
        close(file);
        return;
    }

    // Get the file size
    fseek(fileToSend, 0, SEEK_END);
    size_t fileSize = ftell(fileToSend);
    fseek(fileToSend, 0, SEEK_SET);

    // Send the file size
    bytes_written = write(file, &fileSize, sizeof(fileSize));
    if (bytes_written != sizeof(fileSize)) {
        perror("Error sending file size");
        fclose(fileToSend);
        close(file);
        return;
    }

    // Send the file content
    while ((nbytes = fread(buf, 1, sizeof(buf), fileToSend)) > 0) {
        bytes_written = write(file, buf, nbytes);
        if (bytes_written != nbytes) {
            perror("Error sending file content");
            fclose(fileToSend);
            close(file);
            return;
        }
        usleep(10000);  // Adjust sleep time as needed
    }

    // Close the file
    fclose(fileToSend);

    // Close the serial port
    close(file);
}

Might try fwrite() instead of write. write() uses a fd, file descriptor and you have a FILE*. It is best to keep all of them similar, fwrite, fread, fopen when using a pointer.

Hello foxsquirrel, Thanks for your kind response.
Content of file is printing as like attached picture. Please go through it.

Can we able to transfer .csv or .txt file as it is. And how to print content with same indent?

That is a carriage return/ line feed issue and a general.Linux / Windows difference. You are sending the file correctly, it is the formatting on your a serial terminal.

I changed settings of serial terminal and works for me. Thank you.

Can we share .txt file as it is to LPC2478 or we need to send it as now i am sending.

That will depend on how the file is being parsed on the LPC2478. I can’t possibly say if it will be fine it not

Hello,
Thanks, files from beaglebone to Teraterm(windows PC) transferred and saved in PC successfully.

Now I am trying to send files from PC to Beaglebone over Serial communication(uart) and save those received files in beaglebone.

I am able send file from Teraterm to Beaglebone and received file shows on minicom but how can i save it in beaglebone?

I have never used serial for file transfer, but minicom can do that assuming terraterm can.

In minicom do CTRL ‘a’ and then ‘r’ to go into receive file mode, select the transfer protocol and then in teraterm send the file/files using the same protocol.

XMODEM,YMODEM,ZMODEM

THE TRUTH ABOUT KERMIT FILE TRANSFER PERFORMANCE

You can also turn on capture in minicom and enter a file name to write all incoming/outgoing text to a file.

Hello, I tried it, but I want to receive files using the C application, which I transferred via TeraTerm (Windows).

I write a c code but am not able to receive and store it in Beaglebone. When I transfer a file from TeraTerm, I will see a log in TeraTerm.

I will attach c code herewith, please go through it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>

#define UART_BUFFER_SIZE 1024
#define MAX_FILENAME_ATTEMPTS 10

void receiveAndStoreFileOverUART(const char *folderPath) {
// Open UART port
int uart_fd = open(“/dev/ttyS1”, O_RDWR | O_NOCTTY);
struct termios uart_config;

if (uart_fd < 0) {
    perror("Error opening UART port");
    return;
}

// Configure UART settings
if (tcgetattr(uart_fd, &uart_config) < 0) {
    perror("Error getting UART configuration");
    close(uart_fd);
    return;
}

uart_config.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
if (tcflush(uart_fd, TCIFLUSH) < 0 || tcsetattr(uart_fd, TCSANOW, &uart_config) < 0) {
    perror("Error setting UART configuration");
    close(uart_fd);
    return;
}

// Read the filename from UART
char fileName[UART_BUFFER_SIZE];
ssize_t fileNameLength;
int attempts = 0;

// Try reading the filename multiple times with a delay
while (attempts < MAX_FILENAME_ATTEMPTS) {
    fileNameLength = read(uart_fd, fileName, sizeof(fileName) - 1);

    if (fileNameLength > 0) {
        // Null-terminate the filename
        fileName[fileNameLength] = '\0';

        // Print received filename
        printf("Received filename: %s\n", fileName);
        break;
    }

    usleep(500000); // Sleep for 500 milliseconds before the next attempt
    attempts++;
}

if (fileNameLength <= 0) {
    perror("Error reading filename from UART");
    close(uart_fd);
    return;
}

// Construct the full path of the received file in the specified folder
char filePath[UART_BUFFER_SIZE + strlen(folderPath)];
snprintf(filePath, sizeof(filePath), "%s%s", folderPath, fileName);

// Open the received file for writing
FILE *file = fopen(filePath, "wb");

if (file != NULL) {
    // Read and write data until no more data is received
    char buffer[UART_BUFFER_SIZE];
    ssize_t bytesRead;
    size_t totalBytesWritten = 0;

    while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0) {
        size_t bytesWritten = fwrite(buffer, 1, bytesRead, file);
        totalBytesWritten += bytesWritten;

        if (bytesWritten < bytesRead) {
            perror("Error writing to file");
            break;
        }
    }

    printf("Received and stored %zu bytes of data\n", totalBytesWritten);

    // Close the file
    fclose(file);
} else {
    perror("Error opening file for writing");
}

// Close UART port
close(uart_fd);
printf("UART port closed\n");

}

int main(void) {
// Specify the folder path to store the received files
const char *storageFolderPath = “/home/debian/BLE/”;

// Receive and store the file over UART
receiveAndStoreFileOverUART(storageFolderPath);

return 0;

}

Output of above code -
./uart_receive11.out
Error reading filename from UART: Success

Ok a couple of points which may help you debug this.

Serial port stuff can be complicated as there are many options to set.

You are setting some optons " B9600 | CS8 | CREAD | CLOCAL" however what are all of the other options set to by default, or have be previosuly set by something else. Should you be disabling anything ?

As an example I have some code that opens a serial port which works for me. This is my config. Note I an opening in non blocking mode as I can’t afford anything to block/ don’t want to block.

int openAdaptorPort(const char* dev)
{
   int fd;
   struct termios options;

   fd = open(dev,O_RDWR | O_NOCTTY | O_NDELAY);

   if(fd == -1) {
      return -1;
   }

   tcgetattr(fd, &options);
   options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

   cfsetispeed(&options, B9600);
   cfsetospeed(&options, B9600);

   options.c_cflag |= (CLOCAL | CREAD);
   tcsetattr(fd, TCSANOW, &options);

   fcntl(fd, F_SETFL, 0);

   return fd;

}

Here I am making sure certain flags are not set. Might be needed or not I don’t know, but this works for me. Obviously if you need to use blocking mode, don’t include the O_NDELAY flag.

Also use the cfsetispeed() and cfsetospeed() to set the baud rate.
It may be that OR’ing c_cflag with B9600 is the same, but those function are there for a reason. You could be inadvertently setting other options.

As it appears you are using blocking mode, unless non blocking is set by default,

read() must be returning something. If it returns 0 then you are probably in non blocking mode. It could also be returning and error ( < 0 ) in which case for debugging purposes you should probably print out the error returned. It may help you figure out what is going on.

If in blocking mode there should be some default timeouts set. These could be a problem. You should probably explicitly set them to make sure they are suitable for your needs.

When sending the filename, is the line terminated by either “\n” or “\r\n” ?

Read the man page for tcgetattr and read the section on canonical and nocanonical mode.

Again if you need canonical mode, explicitly set it. Don’t assume it is already set.

Hello, thank you for your patience @benedict.hewson. Now when i am send a file(i.e, test.txt) from teraterm(windows) to Beaglebone. The content of file is shown both on teraterm and minicom.

But all content is not stored in test.txt in beaglebone, some content is missing. special characters and other content.

PFA screenshots of minicom(Beaglebone) and teraterm(windows).

  1. Teraterm
    image

  2. Minicom


    missing some data on minicom now, i think some settings related issue.

I will attach c code herewith pls go through it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>

#define UART_BUFFER_SIZE 8192

void receiveAndStoreStringOverUART(const char *folderPath, const char *filename) {
// Open UART port
int uart_fd = open(“/dev/ttyS1”, O_RDWR | O_NOCTTY);
struct termios uart_config;

if (uart_fd < 0) {
    perror("Error opening UART port");
    return;
}

// Configure UART settings (adjust as needed)
if (tcgetattr(uart_fd, &uart_config) < 0) {
    perror("Error getting UART configuration");
    close(uart_fd);
    return;
}

uart_config.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
if (tcflush(uart_fd, TCIFLUSH) < 0 || tcsetattr(uart_fd, TCSANOW, &uart_config) < 0) {
    perror("Error setting UART configuration");
    close(uart_fd);
    return;
}

// Read the string from UART
char buffer[UART_BUFFER_SIZE];
ssize_t bytesRead;

while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0) {
    // Print the received string
    printf("Received string: %.*s\n", (int)bytesRead, buffer);

    // Construct the full path of the file
    char filePath[UART_BUFFER_SIZE + strlen(folderPath) + strlen(filename) + 1];
    snprintf(filePath, sizeof(filePath), "%s%s", folderPath, filename);

    // Open the file for writing
    FILE *file = fopen(filePath, "ab");

    if (file != NULL) {
        // Write the received string to the file
        size_t bytesWritten = fwrite(buffer, 1, bytesRead, file);

        if (bytesWritten < bytesRead) {
            perror("Error writing to file");
        } else {
            printf("Stored %zu bytes of data in %s\n", bytesWritten, filename);
        }

        // Close the file
        fclose(file);
    } else {
        perror("Error opening file for writing");
    }
}

if (bytesRead < 0) {
    perror("Error reading from UART");
}

// Close UART port
close(uart_fd);
printf("UART port closed\n");

}
int main(void) {
// Specify the folder path where you want to store the received files
const char *storageFolderPath = “/home/debian/BLE/”;

// Specify the filename to be used for storing the received data
const char *receivedFilename = "test.txt";

// Receive and store the string over UART
receiveAndStoreStringOverUART(storageFolderPath, receivedFilename);

return 0;

}

How is Terraterm sending the files, what protocol is it using ?

What special characters are missing ?

Did you read the man page for the differences in canonical and non canonical mode ?
In canonical mode the max line length is 4096 characters. Anything over that will get truncated. How long are your lines of text ?

Hello,
Yes, i have read man page of tcgetattr. Also difference’s in canonical and noncanonical mode.

Now i use non-canonical mode and receives one file and stores in Beaglebone. But i want to receive 6 files one by one and stores it in beaglebone.

Please share your outputs on it.

Thanks,
Avinash

Again I will say, how is Terraterm sending multiple files ? Unless you can understand the sending mechanism, you can’t write the receiving code.

If you are not sure write a small program on the Beagle that just writes the raw bytes it gets from the serial port to a file. Add a signal handler so you can exit cleanly. Then run it.

Create some small test files and send them from Terraterm.
Once sent, exit the Beaglebone program.

Look at the raw data written by the Beaglebone using a hex editor.
That way you should be able to see how multiple files are being transmitted.

the Below attached receiving and storing code written on beaglebone. Which receives and write content to file and file is stored in the beaglebone.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#define UART_BUFFER_SIZE 8192

void receiveAndStoreStringOverUART(const char *folderPath, const char *filename) {
// Open UART port
int uart_fd = open(“/dev/ttyS1”, O_RDWR | O_NOCTTY);
struct termios uart_config;
if (uart_fd < 0) {
perror(“Error opening UART port”);
return;
}

// Configure UART settings (adjust as needed)
if (tcgetattr(uart_fd, &uart_config) < 0) {
    perror("Error getting UART configuration");
    close(uart_fd);
    return;
}

// Set baud rate to 9600
cfsetispeed(&uart_config, B9600);
cfsetospeed(&uart_config, B9600);

// Set data format to 8N1 (8 data bits, no parity, 1 stop bit)
uart_config.c_cflag &= ~PARENB;
uart_config.c_cflag &= ~CSTOPB;
uart_config.c_cflag &= ~CSIZE;
uart_config.c_cflag |= CS8;

// Disable hardware flow control
uart_config.c_cflag &= ~CRTSCTS;

// Enable receiver and local mode
uart_config.c_cflag |= CREAD | CLOCAL;
// Set input mode to non-canonical and disable echo
uart_config.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

// Set the minimum number of characters for non-canonical read
uart_config.c_cc[VMIN] = 1;

// Set the timeout in deciseconds for non-canonical read
uart_config.c_cc[VTIME] = 0;

// Apply UART configuration
if (tcsetattr(uart_fd, TCSANOW, &uart_config) < 0) {
    perror("Error setting UART configuration");
    close(uart_fd);
    return;
}

// Read the string from UART
char buffer[UART_BUFFER_SIZE];
ssize_t bytesRead;
while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0) {
    // Print the received string
    printf("Received string: %.*s\n", (int)bytesRead, buffer);

    // Construct the full path of the file
    char filePath[UART_BUFFER_SIZE + strlen(folderPath) + strlen(filename) + 1];
    snprintf(filePath, sizeof(filePath), "%s%s", folderPath, filename);
    // Open the file for writing in binary mode to preserve special characters
    FILE *file = fopen(filePath, "ab");
    if (file != NULL) {
        // Write the received string to the file
        size_t bytesWritten = fwrite(buffer, 1, bytesRead, file);
        if (bytesWritten < bytesRead) {
            perror("Error writing to file");
        } else {
            printf("Stored %zu bytes of data in %s\n", bytesWritten, filename);
        }

        // Close the file
        fclose(file);
    } else {
        perror("Error opening file for writing");
    }
}

if (bytesRead < 0) {
    perror("Error reading from UART");
}

// Close UART port
close(uart_fd);
printf("UART port closed\n");

}

int main(void) {
// Specify the folder path where you want to store the received files
const char *storageFolderPath = “/home/debian/BLE/”;

// Specify the filename to be used for storing the received data
const char *receivedFilename = "PRO_REC.TXT";

// Receive and store the string over UART
receiveAndStoreStringOverUART(storageFolderPath, receivedFilename);

return 0;

}

I 6 files case, i am sending files one by one in teraterm. The content of files printed both on teraterm and minicom.

i will attach c code for it. Please go through it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#define UART_BUFFER_SIZE 8192

typedef struct {
const char *filename;
} FileDetails;

void receiveAndStoreFilesOverUART(const char *folderPath, const FileDetails *files, int numFiles) {
// Open UART port
int uart_fd = open(“/dev/ttyS1”, O_RDWR | O_NOCTTY);
struct termios uart_config;
if (uart_fd < 0) {
perror(“Error opening UART port”);
return;
}

// Configure UART settings (adjust as needed)
if (tcgetattr(uart_fd, &uart_config) < 0) {
    perror("Error getting UART configuration");
    close(uart_fd);
    return;
}

// Set baud rate to 9600
cfsetispeed(&uart_config, B9600);
cfsetospeed(&uart_config, B9600);

// Set data format to 8N1 (8 data bits, no parity, 1 stop bit)
uart_config.c_cflag &= ~PARENB;
uart_config.c_cflag &= ~CSTOPB;
uart_config.c_cflag &= ~CSIZE;
uart_config.c_cflag |= CS8;

// Disable hardware flow control
uart_config.c_cflag &= ~CRTSCTS;

// Enable receiver and local mode
uart_config.c_cflag |= CREAD | CLOCAL;

// Set input mode to non-canonical and disable echo
uart_config.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

// Set the minimum number of characters for non-canonical read
uart_config.c_cc[VMIN] = 1;

// Set the timeout in deciseconds for non-canonical read
uart_config.c_cc[VTIME] = 0;

// Apply UART configuration
if (tcsetattr(uart_fd, TCSANOW, &uart_config) < 0) {
    perror("Error setting UART configuration");
    close(uart_fd);
    return;
}

// Receive and store each file
for (int i = 0; i < numFiles; i++) {
    // Read the file content from UART
    char buffer[UART_BUFFER_SIZE];
    ssize_t bytesRead;

    // Construct the full path of the file
    char filePath[strlen(folderPath) + strlen(files[i].filename) + 1];
    snprintf(filePath, sizeof(filePath), "%s%s", folderPath, files[i].filename);

    // Open the file for writing in binary mode to preserve special characters
    FILE *file = fopen(filePath, "wb");
    if (file != NULL) {
        while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0) {
            // Write the received content to the file
            size_t bytesWritten = fwrite(buffer, 1, bytesRead, file);
            if (bytesWritten < bytesRead) {
                perror("Error writing to file");
                break;
            }
        }

        if (bytesRead < 0) {
            perror("Error reading from UART");
        }

        // Close the file
        fclose(file);
    } else {
        perror("Error opening file for writing");
    }
}

// Close UART port
close(uart_fd);
printf("UART port closed\n");

}

int main(void) {
// Specify the folder path where you want to store the received files
const char *storageFolderPath = “/home/debian/BLE/”;

// Specify the filenames of the received files
FileDetails files[] = {
    {"1.OP_REC.TXT"},
    {"2.PAT_REC.TXT"},
    {"3.JAR_REC.TXT"},
    {"4.DIA_ID.TXT"},
    {"5.DIA_REC.TXT"},
    {"6.PRO_REC.TXT"}
};
int numFiles = sizeof(files) / sizeof(files[0]);

// Receive and store the files over UART
receiveAndStoreFilesOverUART(storageFolderPath, files, numFiles);

return 0;

}

this not write content to files and file not stores to beaglebone.

Regards,
Avinash

You need to iterate your array.

use a for loop
files[i]
size_t i = 0; i<5; i++

Basically rinse and repeat those steps 6 times, note that your array starts at 0 so the counter is one less.

Hello, Thank you for your suggestions. I have tried all the solutions that you have suggested.

Now I have source code, which receives file content transferred by TeraTerm(windows) and stores it in one file on beaglebone. But I want to store it in 6 files and I am transferring 6 files one by one from TeraTerm.

I have given stopflag in the code, after that it stores content in each file but not all content, it stores only 48 bytes(maximum) in one file.

I will attach the c code herewith. Please go through it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#define UART_BUFFER_SIZE 8192

void receiveAndStoreStringOverUART(const char *folderPath, const char *filenames, int numFiles) {
// Open UART port
int uart_fd = open(“/dev/ttyS1”, O_RDWR | O_NOCTTY);
struct termios uart_config;
if (uart_fd < 0) {
perror(“Error opening UART port”);
return;
}

// Configure UART settings (adjust as needed)
if (tcgetattr(uart_fd, &uart_config) < 0) {
    perror("Error getting UART configuration");
    close(uart_fd);
    return;
}

// Set baud rate to 9600
cfsetispeed(&uart_config, B9600);
cfsetospeed(&uart_config, B9600);

// Set data format to 8N1 (8 data bits, no parity, 1 stop bit)
uart_config.c_cflag &= ~PARENB;
uart_config.c_cflag &= ~CSTOPB;
uart_config.c_cflag &= ~CSIZE;
uart_config.c_cflag |= CS8;

// Disable hardware flow control
uart_config.c_cflag &= ~CRTSCTS;

// Enable receiver and local mode
uart_config.c_cflag |= CREAD | CLOCAL;
// Set input mode to non-canonical and disable echo
uart_config.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

// Set the minimum number of characters for non-canonical read
uart_config.c_cc[VMIN] = 1;

// Set the timeout in deciseconds for non-canonical read
uart_config.c_cc[VTIME] = 0;

// Apply UART configuration
if (tcsetattr(uart_fd, TCSANOW, &uart_config) < 0) {
    perror("Error setting UART configuration");
    close(uart_fd);
    return;
}

// Receive and store each file
for (int i = 0; i < numFiles; i++) {
    // Read the string from UART
    char buffer[UART_BUFFER_SIZE];
    ssize_t bytesRead;

// int stopFlag = 0;

// while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0 && !stopFlag) {
while ((bytesRead = read(uart_fd, buffer, sizeof(buffer))) > 0) {
// Print the received string
printf(“Received string: %.*s\n”, (int)bytesRead, buffer);

        // Construct the full path of the file
        char filePath[UART_BUFFER_SIZE + strlen(folderPath) + strlen(filenames[i]) + 1];
        snprintf(filePath, sizeof(filePath), "%s%s", folderPath, filenames[i]);
        // Open the file for writing in binary mode to preserve special characters
        FILE *file = fopen(filePath, "ab");
        if (file != NULL) {
            // Write the received string to the file
            size_t bytesWritten = fwrite(buffer, 1, bytesRead, file);
            if (bytesWritten < bytesRead) {
                perror("Error writing to file");
            } else {
                printf("Stored %zu bytes of data in %s\n", bytesWritten, filenames[i]);
            }

            // Close the file
            fclose(file);
        } else {
            perror("Error opening file for writing");
        }
         // Check if the user wants to stop
       // if (bytesRead < UART_BUFFER_SIZE) {
       //     stopFlag = 1;

// }

    }

    if (bytesRead < 0) {
        perror("Error reading from UART");
    }
}

// Close UART port
close(uart_fd);
printf("UART port closed\n");

}

int main(void) {
// Specify the folder path where you want to store the received files
const char *storageFolderPath = “/home/debian/BLE/”;

// Specify the file names to be used for storing the received data
const char *filenames[] = {
    "OP_REC5.TXT",
    "PAT_REC5.TXT",
    "JAR_REC5.TXT",
    "DIA_ID5.TXT",
    "DIA_REC5.TXT",
    "PRO_REC5.TXT"
};
int numFiles = sizeof(filenames) / sizeof(filenames[0]);

// Receive and store the string over UART
receiveAndStoreStringOverUART(storageFolderPath, filenames, numFiles);

return 0;

}

Regards,
Avinash

You really need to rethink your whole approach to this.

Problems.

Firstly you are passing an 8K buffer to read. In both canocnical and non-canonical mode the input buffer is limited to 4095 characters.

Besides that, you are sending multiple files.
How does the Beaglebone know when one files ends and the next begins ?

Either concat all of the files into one, with some sort of text in the actual file to delimit the files and then once the single file is downloaded process it to look for the file delimiters and break it into multiple files. Or just handle all of the data as a single file.
Even if you send all the data in a single file, how does the Beagle know it has correctly received the whole file ?
What if the cable gets disconnected part way through a transfer ?

OR

You should be looking at using a proper file transfer protocol to do this. Terraterm should support them all. From memory at the very least you need to use YModem if you need to transfer multiple files. ZModem is better but more complicated.

It would also be helpful if all of the code was inside a code block, rather than split.
Don’t know if that is an issue with the website or how you are copying the code.
have you got ``` in your code somewhere ?

Hello benedict,

All data is stores in one file already but i want to store it in separate files.
For example if i transfer 6 files one by one from TeraTerm it should store in 6 files on beaglebone.

Regards,
Avinash

How can the Beagle tell where the end of the first file is and the start of the second file ? Where the end of the second file is and the start of the third file ? etc.

All it is getting are bytes on the serial port.