-1

I was implementing FTP client to download file from server. I used the command in the below sequence. I could succeed in downloading the file and the connection was terminated gracefully however, the content downloaded is not the same as the content in the original file. I could see some additional [NUL] characters displayed when I open it using notepad++ and notepad displays it as space. I have to get rid of this.

Soon, I set the PASV mode, I initiate data connection. Once the data connection is established successfully, I trigger RETR command, and after getting response from server, i initiate reading data from data socket.

I am using GCC Cygwin on windows machine to execute FTP client.

Please help me out guys. Where have i gone wrong.?

**CLIENT**:
CONNECTION ESTABLISHMENT

**********************************
CONNECTING TO [abc.def.ghi.jkl]:[21]
Client connected to [abc.def.ghi.jkl] successfully..

**SERVER**:
=========
220-FileZilla Server version 0.9.41 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/

**********************************

**CLIENT**:
=========
Sending Username: abc

FTP COMMAND: USER abc

**SERVER**:
=========
331 Password required for abc

**********************************

**CLIENT**:
=========
Sending Password: ******

FTP COMMAND: PASS ******

**SERVER**:
=========
230 Logged on

**********************************

**CLIENT**:
=========
CHANGING WORKING DIRECTORY TO [/test]

FTP COMMAND: CWD /test

**SERVER**:
=========
250 CWD successful. "/test" is current directory.


**********************************

**CLIENT**:
=========
SET TYPE-A MODE

FTP COMMAND: TYPE A

**SERVER**:
=========
200 Type set to A

**********************************

**CLIENT**:
=========
SET PASV MODE

FTP COMMAND: PASV

**SERVER**:
=========
227 Entering Passive Mode (abc,def,ghi,jkl,4,62)

**********************************
CONNECTING TO [abc.def.ghi.jkl]:[1086]
Client connected to [abc.def.ghi.jkl] successfully..

**********************************

**CLIENT**:
=========
RETRIEVE FILE: [abc.txt]

FTP COMMAND: RETR abc.txt

**SERVER**:
=========
150 Connection accepted

*******************************************

DOWNLOADING FILE..
FILE DOWNLOAD COMPLETE [D:\FTP_Client/abc.txt]

*******************************************

**SERVER**:
=========
226 Transfer OK

**********************************

**CLIENT**:
=========
LOGGING OUT..

FTP COMMAND: QUIT

**SERVER**:
=========
221 Goodbye
Vasanth
  • 128
  • 1
  • 18
  • Show us some code! + Your title says "spaces", but the question says "[nul]". + Could you upload the original and the downloaded file somewhere for us? Or post a hex dump to show the actual difference? – Martin Prikryl Sep 21 '16 at 06:18
  • please find the link below. Both the files (original and the downloaded file attached for your reference) https://drive.google.com/drive/folders/0B_KvTQ5pT5z6Yy14NHFMVkJ0T0U – Vasanth Sep 21 '16 at 09:10
  • Good. But show us the code! – Martin Prikryl Sep 21 '16 at 09:19
  • Am sorry. I cant show the code or the excerpts of it due to security reasons of the company. The log which i shared is the modified version to hide sensitive data. May be if you suspect anything, you can tell me where i can look more into. I have strictly used the above commands to establish ctrl and data socket as shown in the log. At wireshark level, i could see the space (0x20) both using filezilla client as well as the client am implementing. Somehow the filezilla client removes those spaces. And i am using stream mode to download file. – Vasanth Sep 21 '16 at 09:25
  • The difference is not about spaces, not sure what you mean. The file is corrupted, there are pieces of text missing. I suspect your code is just wrong. It's not matter of using wrong protocol commands. You probably read the socket incorrectly. If you do not want to share the code, I'm voting to close your question as it is pointless. – Martin Prikryl Sep 21 '16 at 09:29
  • It's your task to post a [mcve]. – Martin Prikryl Sep 21 '16 at 09:31
  • You don't have to down vote for that. As said it's as per company's policy I can't share any code though it's age old FTP am implementing. And I told earlier that i can see the spaces (0x20) in Wireshark logs being padded. Which means, the TCP packets have those. It has nothing to do with socket reading. – Vasanth Sep 21 '16 at 11:59
  • Which part of FTP client code you want me to share? I will try to replicate the code. – Vasanth Sep 21 '16 at 12:01
  • We do not care what you see in Wireshark. All we care about is what is in your question. And your question does not include enough information to debug your problem. Hence the downvote. We need [mcve] – Martin Prikryl Sep 21 '16 at 12:15

1 Answers1

0

It was a "write" system call (programming) error. Instead of writing the received buffer length, I was writing the entire size of buffer which was member to zero. And my sincere apologies for not sharing the code excerpts. It's the company policy :( .

Vasanth
  • 128
  • 1
  • 18