FTP related classes

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I'll be working with FTP uploads/downloads. May
i ask for some pointers to relevant and useful
classes already prepared for such task in the
DotNet 2.0 framework.

I'm thinking FTPConnection, UserInfo, etc.

The ultimate help would be this.
FTPConnection connection =
new FTPConnection();
connection.IP = "1.2.3.4:5678";
connection.user = "god";
connection.password = "god1234";
connection.remoteDir = "\all\things\good";
connection.localDir = "Z:\godlike stuff";
connection.Upload(fileList);
 
K said:
I'll be working with FTP uploads/downloads. May
i ask for some pointers to relevant and useful
classes already prepared for such task in the
DotNet 2.0 framework.

I'm thinking FTPConnection, UserInfo, etc.

The ultimate help would be this.
FTPConnection connection =
new FTPConnection();
connection.IP = "1.2.3.4:5678";
connection.user = "god";
connection.password = "god1234";
connection.remoteDir = "\all\things\good";
connection.localDir = "Z:\godlike stuff";
connection.Upload(fileList);

FtpWebRequest can do the most simple stuff.

See code snippet below.

Arne

============================================

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);
}
 
I use this
http://www.rebex.net/ftp.net/

I find it very good, and when I needed some help with a problem the support
was astounding. The guy manually analysed the request/response data etc
with the server and told my company how to fix the server (there was nothing
wrong with the client components). Highly recommended by me :-)


Pete
 
I'll be working with FTP uploads/downloads. May
FtpWebRequest can do the most simple stuff.

I've found a class called WebClient and i've
made it work the way i wished. However, i'm
afraid that it's an old tool and i'd prefer
to use more modern versions (up to v2.0, at
least until november).

For instance, i've noticed that there seems
not to exist a facility for getting a list of
all files in a remote directory. Is that
because WebClient shouldn't be used?
 
K said:
I've found a class called WebClient and i've
made it work the way i wished. However, i'm
afraid that it's an old tool and i'd prefer
to use more modern versions (up to v2.0, at
least until november).

For instance, i've noticed that there seems
not to exist a facility for getting a list of
all files in a remote directory. Is that
because WebClient shouldn't be used?

WebClient is current.

But WebClient is even more simple than FtpWebRequest.

You can list files with FtpWebRequest:

FtpWebRequest req =
(FtpWebRequest)WebRequest.Create("ftp://ftp.netscape.com/");
req.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse resp = (FtpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
Console.WriteLine(sr.ReadToEnd());

Arne
 
I've found a class called WebClient and i've
WebClient is current.

But WebClient is even more simple than FtpWebRequest.

You can list files with FtpWebRequest:

FtpWebRequest req = (FtpWebRequest)WebRequest
.Create("ftp://ftp.netscape.com/");
req.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse resp = (FtpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
Console.WriteLine(sr.ReadToEnd());

Thanks for the answer! Now, i wonder also why
you use the factory from WebRequest and then
cast the result into FtpWebRequest? I saw that
FtpWebRequest class has its own Create method...
 
K said:
Thanks for the answer! Now, i wonder also why
you use the factory from WebRequest and then
cast the result into FtpWebRequest? I saw that
FtpWebRequest class has its own Create method...

Not in my version !

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top