Please register or login. There are 0 registered and 450 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s November 30 - 03:34pm EST 
Hardware Analysis
Forums Product Prices

  Latest Topics 

More >>


  You Are Here: 
/ Forums / Programming /

  c# FTP subfolders 
 Date Written 
jean pierre bal Jul 02, 2010, 11:09pm EDT Report Abuse

can anybody help me with a small problem i'm having with this project?
i'm trying to write a little program that downloads all files from an FTP server into a directory on my hardrive.
now the problem as many probably already see comming is that there is no real structure on this FTP server and i just need to download the files and not the complete folders (people uploading there complete folder of data instead of just uploading the file inside it :/)

anybody that can help me? i guess the main part of my problem is that i don't know how you can "detect" if somethings a folder or not.

here is what i have sofar

my download class
private void Download(string filePath, string fileName)
FtpWebRequest reqFTP;
//filePath = <<The full path where the file is to be created.>>,
//fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);

catch (Exception ex)

and how i download all files from the FTP server at the moment:
private void btnDownloadAll_Click(object sender, EventArgs e)
string[] files = GetFileList();
foreach (string file in files)

i realize its probably fairly simple but i am new to using FTP in c# and if i google it i usually end up at rebex trying to sell me a library for 299 dollars

thanks in advance, JP

Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
Afrow UK Jul 04, 2010, 05:54am EDT Report Abuse
>> Re: c# FTP subfolders
I don't see any code creating folders here... Perhaps you need to explain exactly what is happening during the download.

I like: Programming, Gym, University
Music: House, Dubstep, D&B, Trance, Metal
jean pierre bal Jul 04, 2010, 07:53am EDT Report Abuse
>> Re: c# FTP subfolders
well i don't need to create a folder but the FTP server i need to download all the files from has loads and loads of submaps and i don't need to download the folders but only the files.

anyway i solved the problem with a bit of help from somebody that pm'd me and gave me an example how to do it with regex, check if the filename has an extention, if not its a folder, if yes its a file :p



  Topic Tools 
RSS UpdatesRSS Updates

  Related Articles 

A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.