PC Review


Reply
Thread Tools Rate Thread

C# FTP client using TcpClient class -- please help

 
 
almurph@altavista.com
Guest
Posts: n/a
 
      5th Mar 2008
Folks,

I'm trying to use C# to connect to an FTP server to upload some
files. I'm calling:

System.Net.Sockets.TcpClient mtTCPClient = new
System.Net.Sockets.TcpClient(url, 21);


The problem is though I know this server accepts a username and
password but I dont know where to put them. I dont see a constructor
for this in the API.

I have that funny feeling that I'm doing something wrong! Or that I'm
missing something. Can anyone help please. Any comments/suggestions/
things that I should know/code-samples much appreciated.

Thanks,
Al.
 
Reply With Quote
 
 
 
 
parez
Guest
Posts: n/a
 
      5th Mar 2008
On Mar 5, 11:43 am, "almu...@altavista.com" <almu...@altavista.com>
wrote:
> Folks,
>
> I'm trying to use C# to connect to an FTP server to upload some
> files. I'm calling:
>
> System.Net.Sockets.TcpClient mtTCPClient = new
> System.Net.Sockets.TcpClient(url, 21);
>
> The problem is though I know this server accepts a username and
> password but I dont know where to put them. I dont see a constructor
> for this in the API.
>
> I have that funny feeling that I'm doing something wrong! Or that I'm
> missing something. Can anyone help please. Any comments/suggestions/
> things that I should know/code-samples much appreciated.
>
> Thanks,
> Al.


Hi Al,

After opening the connection to 21 you will have to write code to send
ftp commands (USER,PWD BY etc).
And your class will have the construcotr for taking username password
and stuff..


Or use 3rd party components.

check this out

http://www.google.com/search?sourcei...nt%20in%20.net
 
Reply With Quote
 
almurph@altavista.com
Guest
Posts: n/a
 
      5th Mar 2008
On Mar 5, 4:55*pm, parez <psaw...@gmail.com> wrote:
> On Mar 5, 11:43 am, "almu...@altavista.com" <almu...@altavista.com>
> wrote:
>
>
>
>
>
> > Folks,

>
> > * * * * I'm trying to use C# to connect to an FTP server to upload some
> > files. I'm calling:

>
> > System.Net.Sockets.TcpClient mtTCPClient = new
> > System.Net.Sockets.TcpClient(url, 21);

>
> > * * * * The problem is though I know this server accepts a username and
> > password but I dont know where to put them. I dont see a constructor
> > for this in the API.

>
> > * * * * I have that funny feeling that I'm doing something wrong! Or that I'm
> > missing something. Can anyone help please. Any comments/suggestions/
> > things that I should know/code-samples much appreciated.

>
> > Thanks,
> > Al.

>
> Hi Al,
>
> After opening the connection to 21 you will have to write code to send
> ftp commands (USER,PWD BY etc).
> And your class will have the construcotr for taking username password
> and stuff..
>
> Or use 3rd party components.
>
> check this out
>
> http://www.google.com/search?sourcei...t%20in%20.net- Hide quoted text -
>
> - Show quoted text -


Can you help me please, to get me started?

Thanks,
Al.
The stupid one.
 
Reply With Quote
 
parez
Guest
Posts: n/a
 
      5th Mar 2008
On Mar 5, 11:59 am, "almu...@altavista.com" <almu...@altavista.com>
wrote:
> On Mar 5, 4:55 pm, parez <psaw...@gmail.com> wrote:
>
>
>
> > On Mar 5, 11:43 am, "almu...@altavista.com" <almu...@altavista.com>
> > wrote:

>
> > > Folks,

>
> > > I'm trying to use C# to connect to an FTP server to upload some
> > > files. I'm calling:

>
> > > System.Net.Sockets.TcpClient mtTCPClient = new
> > > System.Net.Sockets.TcpClient(url, 21);

>
> > > The problem is though I know this server accepts a username and
> > > password but I dont know where to put them. I dont see a constructor
> > > for this in the API.

>
> > > I have that funny feeling that I'm doing something wrong! Or that I'm
> > > missing something. Can anyone help please. Any comments/suggestions/
> > > things that I should know/code-samples much appreciated.

>
> > > Thanks,
> > > Al.

>
> > Hi Al,

>
> > After opening the connection to 21 you will have to write code to send
> > ftp commands (USER,PWD BY etc).
> > And your class will have the construcotr for taking username password
> > and stuff..

>
> > Or use 3rd party components.

>
> > check this out

>
> >http://www.google.com/search?sourcei...in%20.net-Hide quoted text -

>
> > - Show quoted text -

>
> Can you help me please, to get me started?
>
> Thanks,
> Al.
> The stupid one.


This mite be a good starting point

http://www.ondotnet.com/pub/a/dotnet.../ftpdotnet.htm
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      5th Mar 2008
On Wed, 05 Mar 2008 08:59:29 -0800, (E-Mail Removed)
<(E-Mail Removed)> wrote:

> Can you help me please, to get me started?


If you want to implement an FTP client from scratch, this is the place to
start:
http://www.faqs.org/rfcs/rfc765.html

Otherwise, you probably would be better off using the built-in support for
FTP. Here's a starting point for that:
http://msdn2.microsoft.com/en-us/lib...ebrequest.aspx

Pete
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      6th Mar 2008
(E-Mail Removed) wrote:
> I'm trying to use C# to connect to an FTP server to upload some
> files. I'm calling:
>
> System.Net.Sockets.TcpClient mtTCPClient = new
> System.Net.Sockets.TcpClient(url, 21);
>
>
> The problem is though I know this server accepts a username and
> password but I dont know where to put them. I dont see a constructor
> for this in the API.
>
> I have that funny feeling that I'm doing something wrong! Or that I'm
> missing something. Can anyone help please. Any comments/suggestions/
> things that I should know/code-samples much appreciated.


TcpClient first argument is not an URL, but just a host name.

..NET has built in FTP support since .NET 2.0 - code snippet:

public static void Upload(string localfile, string ftpurl, bool
bin)
{
FtpWebRequest req = (FtpWebRequest)WebRequest.Create(ftpurl);
req.Method = WebRequestMethods.Ftp.UploadFile;
req.UseBinary = bin;
if(bin)
{
Stream instm = new FileStream(localfile, FileMode.Open,
FileAccess.Read);
Stream outstm = req.GetRequestStream();
byte[] b = new byte[10000];
int n;
while((n = instm.Read(b, 0, b.Length)) > 0)
{
outstm.Write(b, 0, n);
}
instm.Close();
outstm.Close();
}
else
{
StreamReader sr = new StreamReader(localfile);
StreamWriter sw = new StreamWriter(req.GetRequestStream());
string line;
while((line = sr.ReadLine()) != null)
{
sw.WriteLine(line);
}
sr.Close();
sw.Close();
}
FtpWebResponse resp = (FtpWebResponse)req.GetResponse();
Console.WriteLine(resp.StatusCode);
}

If you reall want to implement a FTP client using TcpClient, then
look at http://www.vajhoej.dk/arne/eksperten...007_03/xftp.cs !

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pb with TcpClient class and NTP server Kirk Microsoft C# .NET 2 12th Oct 2005 01:21 PM
TCPClient and TCPListener Class =?Utf-8?B?SGVscFdpdGhGVFA=?= Microsoft Dot NET 0 14th Apr 2005 01:37 AM
Getting IP of Client with TcpClient Kintwa Microsoft VB .NET 1 21st Jun 2004 09:32 PM
TcpClient and Socket class Bjoern Microsoft Dot NET Compact Framework 1 27th Jan 2004 03:46 PM
TcpClient Class Javier Ros Microsoft Dot NET Compact Framework 1 22nd Jan 2004 12:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 AM.