471,349 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

FTP related classes

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);

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 27 '08 #1
6 933
K Viltersten wrote:
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);
}
Jul 27 '08 #2
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

Jul 27 '08 #3
>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.
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?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 27 '08 #4
K Viltersten wrote:
>>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.

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
Jul 27 '08 #5
>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).

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...

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Jul 27 '08 #6
K Viltersten wrote:
>>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).
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...
Not in my version !

Arne
Jul 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by bonj | last post: by
4 posts views Thread by Sathyaish | last post: by
3 posts views Thread by michael_geller | last post: by
4 posts views Thread by Phill W. | last post: by
3 posts views Thread by Steven Nagy | last post: by
6 posts views Thread by Marco | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.