Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:52:34+00:00 2026-05-25T13:52:34+00:00

I Have written a server and a client to implement FTP and if i

  • 0

I Have written a server and a client to implement FTP and if i create text files and send them they work fine . but as soon as i send files of other formats the received file on the clients end is a corrupted one. here the code where i,m sending the file

           try
           {
              fis=new FileInputStream(filenm);
           }

           catch(FileNotFoundException exc)
           {
              filexists=false;
              System.out.println("FileNotFoundException:"+exc.getMessage());
           }
           if(filexists)
           {
               System.out.println("sent");
               sendBytes(fis, output);
               fis.close();
            }

private static void sendBytes(FileInputStream f,OutputStream op)throws Exception
 {
  byte[] buffer=new byte[1024];
  int bytes=0;

  while((bytes=f.read(buffer))!=-1)
  {
   op.write(buffer,0,bytes);
  }
 }

fis – FileInputStream object
output – OutputStream object (Socket.getOutputStream())

and the client code is:

File f=new File(dir,"file2");
FileOutputStream fos=new FileOutputStream(f);
DataOutputStream dops=new DataOutputStream(fos);
System.out.println("2nd Stage");
while(done)
{
  fc2=br.read();
  if(fc2==-1)
  {
    done=false;
  }
  else
  {
       dops.write(fc2);
  }
}
fos.close();
System.out.println("File Recieved");

am i using the right streams ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:52:35+00:00Added an answer on May 25, 2026 at 1:52 pm

    It sounds like you are sending Binary files in ASCII mode.

    Send TYPE I instead of TYPE A on the control channel before you set up the data channel by sending the PORT or PASV command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a server/client application. Both of them are written in C#. It
I have written a server and a client both as separate apps. They communicate
I am adapting a little rmi client-server application. I have written several things :
I have a simple UDP client server written in C++ on Ubuntu 9.10 where
I have a client-server application written in Java using CORBA for the communication. The
Hey gang. I have just written a client and server in C++ using sys/socket.
I have a client/server program in TCP written in C, and I would like
I have a classic client/server (fat client and database) program written in Delphi 2006.
I just figured out how to implement android c2dm client but on the server
I have written code for server and client sockets. I have used threads using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.