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 7018637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:04:40+00:00 2026-05-27T23:04:40+00:00

I am trying to upload a file to an FTP-server using a URLConnection. There

  • 0

I am trying to upload a file to an FTP-server using a URLConnection. There are no exceptions thrown. I seem to be able to connect to the server. I can download the file (with another peace of the program) without problems if I upload it “manually” (with an FTP client).

I use BufferedOutputStream.write(int). The log shows that I can read the local file (which contains “Hej hej”) and access the bytes in it. Problem is: nothing is written to the server file. When I read the file on the server, it still contains the pre-upload content. The file isn’t updated. I tried BufferedOutputStream.write(String.getBytes()) but that didn’t help.

static public void upload(String string, String file) {
    File file_ = new File(Environment.getExternalStorageDirectory() + "/Android/data/org.sionlinkoping.pingstprayer/files/thanks.txt");
try {
    upload("ftphome.mah.se", user, passwd, "thanks.txt", file_);
}
catch(Exception e) { Log.d("",e.toString()); }
}


static public void upload( String ftpServer, String user, String password,
        String fileName, File source ) throws MalformedURLException,
    IOException
{
    if (ftpServer != null && fileName != null && source != null)
{
    StringBuffer sb = new StringBuffer( "ftp://" );
    // check for authentication else assume its anonymous access.
    if (user != null && password != null)
    {
        sb.append( user );
        sb.append( ':' );
        sb.append( password );
        sb.append( '@' );
    }
    sb.append( ftpServer );
    sb.append( '/' );
    sb.append( fileName );

        BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try
        {
        URL url = new URL( sb.toString() );
        URLConnection urlc = url.openConnection();

            bos = new BufferedOutputStream( urlc.getOutputStream() );
        bis = new BufferedInputStream( new FileInputStream( source ) );

            int i;
        // read byte by byte until end of stream
        while ((i = bis.read()) != -1)
        {
            Log.d("","i:"+i);
            bos.write( i );
        }
        bos.flush();
    }
    finally
    {
        if (bis != null)
            try
            {
                bis.close();
            }
            catch (IOException ioe)
            {
                ioe.printStackTrace();
            }
        if (bos != null)
            try
            {
               bos.close();
            }
            catch (IOException ioe)
            {
                ioe.printStackTrace();
            }
    }
    }
else
{
    System.out.println( "Input not available." );
}
}

The Log shows:

01-07 14:00:50.662: DEBUG/(6925): i:239
01-07 14:00:50.662: DEBUG/(6925): i:187
01-07 14:00:50.662: DEBUG/(6925): i:191
01-07 14:00:50.662: DEBUG/(6925): i:72
01-07 14:00:50.662: DEBUG/(6925): i:101
01-07 14:00:50.662: DEBUG/(6925): i:106
01-07 14:00:50.662: DEBUG/(6925): i:32
01-07 14:00:50.662: DEBUG/(6925): i:104
01-07 14:00:50.662: DEBUG/(6925): i:101
01-07 14:00:50.662: DEBUG/(6925): i:106
01-07 14:00:50.672: DEBUG/(6925): i:10
  • 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-27T23:04:41+00:00Added an answer on May 27, 2026 at 11:04 pm

    The problem lies with your assumption that writing to an FTP URL will result in a file being saved to the server. It won’t. The results are just undefined — it doesn’t work that way.

    There are FTP libraries available; you’ll need to use one. For example, see here.

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

Sidebar

Related Questions

I am trying to upload file to FTP server using php but it is
I'm trying to upload a file to the server using a HTTP multipart form
friends, i am trying to upload file to php server using following tutorial http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html
I'm trying to upload PHP file via php using ftp details as mentioned below.
I'm trying to upload a .avi file to an FTP server with QFtp: void
I am trying to upload file from android sdcard to FTP Web server. For
I'm trying to upload a text file to an FTP server, but I am
I am using C# to upload some file to a ftp server. If the
I'm trying to upload large file (>100Mb) using Apache commons-net FTP library to Secure
I am trying to use ftps to upload file to our FTP server. Login

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.