LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-23-2021, 11:25 PM   #1
rootaccess
Member
 
Registered: Mar 2012
Posts: 311

Rep: Reputation: Disabled
Simple FTP client works great in C, but not in C++ : 500 Unknown Command


I passed in too many characters in the send command for its size. It did not match the actual characters in the send command.

Last edited by rootaccess; 11-25-2021 at 09:14 AM. Reason: i pasted the entire code for viewing, a bit cumbersome to read
 
Old 11-24-2021, 02:00 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,973

Rep: Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334Reputation: 7334
you need to check the return (error) code of the calls like socket, send, connect. (see also perror).
 
Old 11-24-2021, 09:55 AM   #3
rootaccess
Member
 
Registered: Mar 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
I've been doing that for recv. That's what msg1 is for. I then print that to my console. i went ahead and pasted the entire code, anyway. The return from connect would just be 0. It clearly does connect on the socket. It just doesn't allow me to send anymore commands once I connect on the pasv port with another socket and the pasv_port. Clearly, it works in C. It's a C++ thing that Im not sure of.

Last edited by rootaccess; 11-24-2021 at 09:58 AM.
 
Old 11-24-2021, 12:32 PM   #4
EdGr
Senior Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,000

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
This may be a Windows versus Linux problem.

Windows' stdio library does automatic translation of line feed characters into carriage return plus line feed pairs. Linux passes everything though unchanged. Your program's strings may have extraneous carriage returns when run on Windows.
Ed
 
Old 11-24-2021, 01:01 PM   #5
rootaccess
Member
 
Registered: Mar 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled
I got it to work!

This sounds really silly but I had an extra character when I was sending off the size of the PASV command in the send(). It went through because I had enough room for it, but adding the extra character probably remained in the buffer on the server side, muddling with the next command.

First, I started cleaning up. I modified all of the sizes in the commands to strlen(user) for example just to be consistent, since doing user.length() is better reserved for strings which i at one point had to do since I hate dealing with the char assembly in C++. To send a command via FTP, you must send a char *. in C++ that must be a const char or c_str(), it cannot be a string or even a char[].

Once I changed back to strlen for everything, I realized for my pasv command, since that was not a user, pass or stor variable, it had to be explicit. If you look at the size, I ended up putting 7, which was 1 more than it needed. And I did that because I thought I needed to pass off room for a NULL terminator. I did at one point have
Code:
strlen("pasv\r\n")
but then changed it thinking I needed room for another null as mentioned.

Last edited by rootaccess; 11-24-2021 at 01:45 PM.
 
  


Reply

Tags
c++, networking, programming, windows



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newb's first post. Simple bridge works great, but IP routing to bridge is not stable, needs pings. edmonstone Linux - Networking 8 09-22-2016 09:42 AM
when I use ftp://user@ftp.blah.com it works. But when I type just ftp.blah.com says.. hunterhunter Linux - General 15 03-05-2014 09:12 AM
FTP client fails - error says 500 Unknown user tasdca Linux - Server 1 01-30-2013 11:21 AM
Great place, great people, and me feel great to be here rajshekarj LinuxQuestions.org Member Intro 2 10-22-2009 03:34 PM
Sprint Wireless Pantech PX-500 WORKS GREAT! halo14 Linux - Hardware 2 03-12-2009 09:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration