By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,158 Members | 1,385 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,158 IT Pros & Developers. It's quick & easy.

Calling FTP process

P: n/a
I want to write a console application which will connect to another machine
and FTP files from that machine to mine.

Does .Net have classes which would allow me to do this natively in the .Net
platform? (Any examples???)

If the .Net does not have any classes which allow me to do this natively,
how do I call the FTP application and send and receive information back (any

Mar 31 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

.Net 2.0 has built in support using FtpWebRequest, here's an example:

// setup a new ftp upload request, specifying deestination path, user id
and password

FtpWebRequest ftpreq = (FtpWebRequest)WebRequest.Create(serverPath +
ftpreq.Method = WebRequestMethods.Ftp.UploadFile;
ftpreq.Credentials = new NetworkCredential(FTPuserID, FTPpassword);

// read the file to be uploaded into a byte array

StreamReader sourceStream = new StreamReader(sourcePath + sourceFile);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());

// upload the byte array

ftpreq.ContentLength = fileContents.Length;
Stream requestStream = ftpreq.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);

// get the response (note most ftp errors won't trigger the
// catch block below)

FtpWebResponse response = (FtpWebResponse)ftpreq.GetResponse();
Console.WriteLine("upload complete, status {0}",


depending on how your proxies are setup you may also need to switch off
the default web proxy with WebRequest.DefaultWebProxy = null; before
setting up the ftp request.

*** Sent via Developersdex ***
Mar 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.