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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:15:49+00:00 2026-05-20T00:15:49+00:00

The likes of Java, Python, and others have ruined me. I’m trying to automate

  • 0

The likes of Java, Python, and others have ruined me. I’m trying to automate an FTP client by responding to server codes:

For example:

// I know this is ugly, please bear with me

char username[25];
strcat(username, USER); //"USER "
strcat(username, usr); // "foo"
strcat(username, "\n"); // = "USER foo\n"

char password[25];
strcat(password, PASS); //"PASS "
strcat(password, pswd); //"bar"
strcat(password, "\n"); // = "PASS bar\n"


//read/write loop

while (1) { 

    char* responsePtr;
    serverCode = readSocket(sockfd, mybuffer);

    if (serverCode == 221) 
                    break;

    if (serverCode == 220)
        responsePtr = &username;

    if (serverCode == 331)
        responsePtr = &password;

    writeSocket(sockfd, responsePtr);

}

When I try this, it works for USER, but I get some mangled text for PASS:

C->S: USER anonymous
S->C: 331 Please specify the password.
C->S: (??_?PASS random

Can anyone wiser and more experienced than myself give me some C string pointers? Clearly this isn’t working out for me.

  • 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-20T00:15:50+00:00Added an answer on May 20, 2026 at 12:15 am

    You need to initialize your strings before you concatenate to them. Arrays are not initialized by default.

    char username[25] = "";
    char password[25] = "";
    

    For what it’s worth, you can use sprintf to create the strings more easily:

    sprintf(username, "USER %s\n", usr);
    sprintf(password, "PASS %s\n", pswd);
    

    Hopefully you also realize that using fixed size buffers is a recipe for buffer overflow bugs. For security you should make sure to guard against them. It’s annoying, but that’s C for you:

    if (snprintf(username, 25, "USER %s\n", usr)  >= 25 ||
        snprintf(password, 25, "PASS %s\n", pswd) >= 25)
    {
        fprintf(stderr, "buffer overflow\n");
        exit(EXIT_FAILURE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website (python/django) that needs to use a load of Java resources
Possible Duplicate: Java Python Integration I have a large existing codebase written in 100%
I have a background in java, and I'm learning python. I'll need to be
Is there an online Java book like Dive into Python for learning Python? Other
Is there anything in Python that works like the final keyword in Java -
Is there something like python's interactive REPL mode, but for Java? So that I
I have recently started seeing user agents like Java/1.6.0_14 (and variations) on my site
As a matter of fact you have smth like /java/src and /java/test . But
After five years of professional Java (and to a lesser extent, Python) programming and
I am fluent in C++, Java, and Python and can pretty much pick up

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.