473,569 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can anybody help me in a ftp program?


Hi

I am a beginner of programming. These days, I try to
develop a ftp program. But I find it is harder than I
have thought.
I want to post my code, then concentrate on resolving
the multithread problem and the communication problem
between the client and the server.

Can anybody help me or just join the discussion?
Nov 15 '05 #1
5 1485
"fjlpf" <an*******@disc ussions.microso ft.com> wrote in news:054a01c3ac 35
$0************* ***@phx.gbl:

Hi

I am a beginner of programming. These days, I try to
develop a ftp program. But I find it is harder than I
have thought.
I want to post my code, then concentrate on resolving
the multithread problem and the communication problem
between the client and the server.

Can anybody help me or just join the discussion?


Well, start with some palpable question and we will be able to help you...

cheers,
Peter

--
------ooo---OOO---ooo------

Peter Koen - www.kema.at
MCAD CAI/RS CASE/RS IAT

------ooo---OOO---ooo------
Nov 15 '05 #2
Hi "fjlpf",

(Your parents really gave you that name? :) )

"fjlpf" <an*******@disc ussions.microso ft.com> schrieb im Newsbeitrag
news:05******** *************** *****@phx.gbl.. .
I am a beginner of programming. These days, I try to
develop a ftp program. But I find it is harder than I
have thought.
I want to post my code, then concentrate on resolving
the multithread problem and the communication problem
between the client and the server.


As Peter told you already: Ask a question and maybe we could answer it.

And: Please go to google and search a little. Or simply go to
http://www.codeproject.com/csharp/

There you find a lot of stuff about ftp and c#.

Some small examples are:
FTP Component in C# for .NET:
http://www.codeproject.com/csharp/ftp.asp
FTP client library for C#:
http://www.codeproject.com/csharp/ftplibrary.asp
Application for uploading modified Files to a FTP Server
http://www.codeproject.com/csharp/net_ftp_upload.asp

With kind regards,

Konrad
Nov 15 '05 #3

Here is my code of ftp server. And I just extract the
implement of the function of transfering files.
I know it is very awful, so I am here to asked for your
help.

namespace FtpSrvr
{
public class Form1 : System.Windows. Forms.Form
{
private bool srv = true;
private IPAddress ipAddr;
private IPEndPoint ipEP;
public Socket sock_accpt;//port 20
public Socket sock_daccpt;//port 21
private Thread thrd_accpt;//a thread to accept connection
private Thread thrd_Daccpt;

public int total =0;

..........

[STAThread]
static void Main()
{Application.Ru n(new Form1()); }
............... .

private void btStartSrvr_Cli ck(object sender,
System.EventArg s e)
{
this.btStartSrv r.Enabled = false;
ipAddr = IPAddress.Parse ("127.0.0.1" );
IPEndPoint ipEP1 = new IPEndPoint(ipAd dr,20);
sock_accpt = new Socket
(AddressFamily. InterNetwork,So cketType.Stream ,ProtocolType.
Tcp);
sock_accpt.Bind ((EndPoint)ipEP 1);
sock_accpt.List en(5);
//
IPEndPoint ipEP2 = new IPEndPoint(ipAd dr,21);
sock_daccpt = new Socket
(AddressFamily. InterNetwork,So cketType.Stream ,ProtocolType.
Tcp);
sock_daccpt.Bin d((EndPoint)ipE P2);
sock_daccpt.Lis ten(5);

//create new thread to accept connection
thrd_Accpt = new Thread(new ThreadStart(thi s.Thrd_Accpt));
thrd_Accpt.Star t();

}
private void Thrd_Accpt()
{
while(srv)//
{ Socket newClient = sock_accpt.Acce pt();

ThreadStartComm and c = new ThreadStartComm and
(newClient,this .sock_daccpt);

Thread thrd = new Thread(new ThreadStart(c.T hrd_Command));
thrd.Start();
}
}

internal class ThreadStartComm and
{
private Socket _sock;//store the socket created by accept()
private Form1 _form;

public ThreadStartComm and(Socket sock, Form1 form
{ _sock = sock;
_form = form;
}

//this function aims to retrevie command
public void Thrd_Command()
{
_sock.SetSocket Option
(SocketOptionLe vel.Socket,Sock etOptionName.Se ndTimeout,5000
);

byte[] b= System.Text.Enc oding.ASCII.Get Bytes("welcome to
my ftp server");

try
{
_sock.Send(b,0, b.Length,Socket Flags.None);
}
catch(SocketExc eption ex)
{
System.Diagnost ics.Debug.Write ("error to send welcome
message" );
return;
}
_sock.SetSocket Option
(SocketOptionLe vel.Socket,Sock etOptionName.Re ceiveTimeout,2
0000);

byte[] buffer = new byte[1024];
int rcv ;
while(true)
{
try
{
rcv = _sock.Receive(b uffer,0,1024,So cketFlags.None) ;
}
catch(SocketExc eption ex)
{
/*if the client doesn't send command within 20 seconds,the
socket will close.*/

_sock.Close();
return
}
}

string s = System.Text.Enc oding.ASCII.Get String
(buffer,0,rcv);
s = s.ToLower();
int i = s.IndexOf(" ");
string comCode = s.Substring(0,i );
string para = s.Substring(i+1 ,rcv-1-i);
AnalyseCommand( comCode,para);
byte[] buffer = ASCII.GetBytes( "120 new port allocated");
_sock.Send(buff er,0,buffer.Len gth,SocketFlags .None);
}
}

public void AnalyseCommand( string comCode, string para)
{
switch(comCode)
{
case "retr":
{
lock(this._form .sock_daccpt)//
{if(this._form. total<4)
this._form.tota l++;//restrict total connection of Port 21
else
{byte[] buf = System.Text.Enc oding.ASCII.Get Bytes("sorry,
overload");
this._sock.Send (buf,0,buf.Leng th,SocketFlags. None);
return;
}
}
Thread thrd = new Thread(new ThreadStart
(this.ThrdSndFi le));

thrd.Start();// thread to transfer file to client
}
break;
}
case "":...

case "":...
}
}

public void ThrdSndFile(Soc ket accpt, string para)
{
Socket dataclient = this._form.sock _daccpt.Accept( );
FileStream fs;
try
{
fs = new FileStream
(@para,FileMode .Open,FileAcces s.Read,FileShar e.Read);
}
catch(IOExcepti on ex)
{dataclient.Clo se();
return;
}

dataclient.SetS ocketOption
(SocketOptionLe vel.Socket,Sock etOptionName.Se ndTimeout,5000
0);
int rd = 1;

while(rd!=0)
{
//Question:if the client socket collapse, what happen to
//socket of server, does it still push data to TCP's buffer
byte[] buffer = new byte[1024];
rd = fs.Read(buffer, 0,1024);

try
{_sock.Send(buf fer,0,rd,Socket Flags.None);
}
catch(SocketExc eption ex)
{
lock(this._form ._sock_daccpt)
{ this._form.tota l--;
}
_sock.Close();
return;
}
}
}

_sock.Close();
}
}
}
Nov 15 '05 #4

:)
konrad,
my parents' taste isn't awful like me.

with kind regards
Nov 15 '05 #5
Hi!

"fjlpf" <an*******@disc ussions.microso ft.com> schrieb im Newsbeitrag
news:05******** *************** *****@phx.gbl.. .
:)
konrad,
my parents' taste isn't awful like me.


Then everything is ok for me. I hope, my links helped a little.

With kind regards,

Konrad
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2980
by: svenn.are | last post by:
Hi, has anybody thought of / already used graphviz to convert the output of trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does not successfully create a dot file, and 2. I don't really want a UML representation but a compact representation of program execution. Maybe there is some other tool that I am not aware of which...
10
3339
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does anybody know how I could do this?
4
2651
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am...
1
3698
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
2
1481
by: Vic.Dong | last post by:
Hello: Is there anybody how to create hidden folder in public folder or system? I have a any problem. I cannot create hidden folder in public or system folder. Is there anybody who knows the answer to create hidden folder ?
3
2695
by: DurumDara | last post by:
Hi ! I need to speedup my MD5/SHA1 calculator app that working on filesystem's files. I use the Python standard modules, but I think that it can be faster if I use C, or other module for it. I use FSUM before, but I got problems, because I "move" into "DOS area", and the parameterizing of outer process maked me very angry (not working)....
4
2289
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory as the sample. I have trouble translating those samples to working with data coming from my database, so I am hoping that someone could show me a...
2
1538
by: Clemens Vasters | last post by:
"Is anybody from Microsoft reading this?" Well ... actually .... no .... welll ... maybe if you're really lucky. Let me explain ... My name is Clemens Vasters and I am a Program Manager on the Connected Framework team here at Microsoft. Our team owns ASP.NET Web Services, .NET Remoting, WSE, the Windows Workflow Foundation and the Windows...
17
2295
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection to build a compiler? One that will construct a user defined class "on the fly" (literally, the user defines a class, instantiates it, and runs it...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.