Click here to Skip to main content
11,428,004 members (59,936 online)
Click here to Skip to main content

TJFTP - A Visual C++ FTP Client

, 14 Nov 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
A Windows FTP client written without CInternetSession or CFtpConnection classes. Demonstrates manual manipulation of Winsock sockets, FTP principles, and GUI concepts such as List controls with in-place label-editing and column sorting, progress indicators, and reading and writing to the Registry.

Introduction

Ever wondered what goes on behind the scenes when you use an FTP client? What actually happens at the socket level, and what the program does in the background?

TJFTP is a CFormView-derived FTP (File Transfer Protocol) application written in Visual C++ 4 and 5. VC++ had no CInternetSession, CFtpConnection, CAsyncSocket, CSocket, or Socket MFC classes back then, so I wrote in the FTP functionality from scratch, creating custom socket classes to handle the control and data connections. Then I coded the GUI to manipulate directory and file creation, deletion, and transfer once I had the connection, and to stay updated with the progress of operations.

Background

Back in 1996, I was writing some apps for a computer engineering master's final project. I decided to see if I could write a fully functional FTP app that would incorporate some nice GUI stuff. Features I wanted included; a Connection dialog box to allow users to create and save connection profiles in the Registry; List controls with in-place label editing and column sorting on both sides of the connection; double-clicking to initiate file transfers; selecting and transferring multiple files; and a progress indicator to show the user the status of file transfers. Having never programmed before, I bought VS 4 and, after mastering the "Hello World" beginner's app we all write, got to work.

Early in 2005, I stumbled on the source code to TJFTP, which I thought I'd lost. I considered recompiling it in VC++.NET for fun, but I was sure it would blow up, after 8 years and several iterations of Visual C++, Windows, and WinSock. However, it compiled under .NET with no errors, and ran fine on Windows XP.

Some of the Custom Classes

  • CWinsock (csock.cpp): Controls the Winsock subsystem with Startup(), Shutdown() and ErrorBox() functions.
  • CStreamSocket (csock.cpp): Creates and destroys control and data sockets. Creates and accepts connections, and sends and receives data. Handles Winsock events, including asynchronous read and write events to prevent blocking (i.e. freezing until the Winsock calls were done).
  • CFtpConnect (ftpconnect.cpp): A CDialog-based class that opens a dialog box for the user to input connection info into when the the app starts and when the "Connect" button is pushed. Stores connection "profiles" in the Registry so users save their information from session-to-session.
  • CMainView (mainview.cpp): The real "guts" of the program. Handles all the GUI stuff for the main interface, including list controls, pushbuttons, and the progress indicator. Processes Winsock messages, creates sockets from CStreamSocket, listens to connections, and accepts connections and data. Allows user to select binary or ASCII transfer, or lets the program auto detect the transfer mode.

Points of Interest

Documentation: Because I was writing this app as part of a master's thesis, the project had to be documented to software engineering standards. Each subroutine has a complete header comment, and there are comment lines sprinkled liberally throughout the code explaining what's going on. In addition, I wrote a user's manual, and I've also extracted the portion of my thesis that deals with TJFTP. It has detailed information on each subroutine, and program flow diagrams, such as the main flow diagram below (dotted lines are asynchronous Winsock callbacks):

TJFTP Main Program Flow Diagram

The flow diagrams show how convoluted the whole process is, and the difficulty in keeping track of everything going on. Code snippets aren't really appropriate for this article, because there is so much going on. I suggest you grab the flow diagrams, open the code in VS, and dig around.

Functionality: I've tested the recompiled program on WinXP SP1 and SP2, uploading files to my FTP server, then downloading them back to my local machine with both TJFTP and a commercial FTP client. Then I checked the file to see if it matched the original file. The largest file I tested was 300 MB. As you can see from the screenshot above, I also logged on to a commercial server that allows anonymous connections and successfully downloaded files. TJFTP seems very stable, it hasn't crashed on me yet.

Caveat

This program is provided for informational use only. Although I have used it without file corruption or other problems, I make no claims to this effect...do not use it as you would a commercial FTP app. Also, TJFTP is not secure...passwords are sent in plain text and are not encrypted.

History

  • Written Nov '96 - Feb '97 in Visual C++ 4 and 5.
  • Recompiled March, '05 in Visual Studio .NET 2003.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

shellraker
Web Developer
United States United States
My name is Jim Dunne. I'm retired from the US Air Force.

In some of my spare time, I develop some ping/traceroute applications that I first wrote as a Master's in Computer Engineering thesis.

My resume is at http://www.dunnes.net/resume.

Comments and Discussions

 
GeneralGreat Work Pin
climbpys10-Dec-09 2:33
memberclimbpys10-Dec-09 2:33 
GeneralRe: Great Work Pin
shellraker10-Dec-09 9:46
membershellraker10-Dec-09 9:46 
GeneralA comfortable FTP class in .NET Pin
Elmue27-Aug-08 13:20
memberElmue27-Aug-08 13:20 
QuestionProblem regarding execution of the TJFTP Pin
Ahmer.parkar25-Aug-08 23:20
memberAhmer.parkar25-Aug-08 23:20 
AnswerRe: Problem regarding execution of the TJFTP Pin
shellraker27-Aug-08 14:59
membershellraker27-Aug-08 14:59 
QuestionWhy can't I view the previous messages? Pin
kezhu13-Dec-07 13:58
memberkezhu13-Dec-07 13:58 
QuestionWhy can't I view the previous messages? Pin
kezhu13-Dec-07 13:43
memberkezhu13-Dec-07 13:43 
NewsOriginal Source Code Pin
shellraker20-Jun-07 18:12
membershellraker20-Jun-07 18:12 
GeneralTJFTP linking problem Pin
oaa.infocom16-Jun-07 1:45
memberoaa.infocom16-Jun-07 1:45 
Dear ALL

I would like to introduce myself first, Omar Ali, MSc student in the research stage, college of Engineering, Baghdad University, Iraq.
I am making research on (Active Networking System- Security of Active Networks).I found out throughout my research that I need FTP client under windows to help me accomplishing my research.

I request your kind assistance to help providing me with answer to the following question about "TJFTP" software.

"After a successful compilation under MS VC++6 compiler, the linker is failed in linking the source code files. The linking result is shown below:
Output Window
Compiling resources...
Compiling...
tjftpdoc.cpp
csock.cpp
ftpconnect.cpp
mainfrm.cpp
f:\c projects\tjftp_src\mainfrm.cpp(122) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
f:\c projects\tjftp_src\mainfrm.cpp(123) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
stdafx.cpp
tjftp.cpp
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/TJFTPtest.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
Results
TJFTPtest.exe - 4 error(s), 2 warning(s)"

What is the problem please? I need correct building of the TJFTP code. I would like to make some modifications to the original TJFTP software (security, for example). I will, surely, refer to the original TJFTP author and site in references of my thesis. "

Knowing that I have been visited your site and find it related (in some cases) to my research.

Your kind assistance in providing me with answers to this question will help me allot to tackle and overcome the problems I am facing in my research.

I highly appreciate your kind assistance. With best regards.

MSc student
O. Ali
Iraq

GeneralRe: TJFTP linking problem Pin
shellraker20-Jun-07 17:41
membershellraker20-Jun-07 17:41 
General425 can't open data connection Pin
skyramesh26-Apr-07 1:38
memberskyramesh26-Apr-07 1:38 
GeneralVisual C++ 4.0 Pin
tykeenum7-Aug-06 4:10
membertykeenum7-Aug-06 4:10 
Generalproblem Pin
brian scott6-Jul-06 1:37
memberbrian scott6-Jul-06 1:37 
GeneralExcellent Pin
Jason Henderson9-Jan-06 20:02
memberJason Henderson9-Jan-06 20:02 
GeneralGreat piece of code! Pin
Piccinano28-Nov-05 6:08
memberPiccinano28-Nov-05 6:08 
GeneralRe: Great piece of code Pin
shellraker28-Nov-05 13:02
membershellraker28-Nov-05 13:02 
GeneralRe: Great piece of code Pin
Piccinano28-Nov-05 23:11
memberPiccinano28-Nov-05 23:11 
GeneralGood Job! Pin
handychang22-Nov-05 19:16
memberhandychang22-Nov-05 19:16 
GeneralVery very good! Pin
coolzerg22-Nov-05 17:42
membercoolzerg22-Nov-05 17:42 
GeneralVisual C++ 5 Source Code Pin
shellraker23-Nov-05 14:08
membershellraker23-Nov-05 14:08 
GeneralDidnt work so fine Pin
KarstenK15-Nov-05 3:22
memberKarstenK15-Nov-05 3:22 
GeneralRe: Didnt work so fine Pin
shellraker15-Nov-05 14:34
membershellraker15-Nov-05 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 14 Nov 2005
Article Copyright 2005 by shellraker
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid