Jump to content


Photo

Loop Through Directories with C#


  • Please log in to reply
1 reply to this topic

#1 Halo2

Halo2
  • Members
  • 6 posts

Posted 12 May 2005 - 08:28 PM

I am trying to loop through the directories but I cannot seem to get the working directorie to change. What am I missing

static void cgdirectories(string ftpDir)
{
FTPConnection ftp = new FTPConnection();
ftp.Host = "xxx.com";
ftp.Port = 21;
ftp.Username = "xxx";
ftp.Password = "xxx";
ftp.Passive = true;
ftp.ProxyType = sfFTPLib.enumProxyType.ftpProxyTypeNone;
ftp.FTPProxyType = sfFTPLib.enumFTPProxyType.ftpFTPProxyTypeNone;
ftp.Client = "FTP Updater";
ftp.LogFile = "FTPTXR.log";
ftp.ChangeDirectory(ftpDir);
sfFTPLib.enumError err = ftp.Connect();
if(err == sfFTPLib.enumError.ftpErrorSuccess)
{

//if(ftp.ChangeDirectory(ftpDir) == sfFTPLib.enumError.ftpErrorSuccess)
//{

//}

if(ftp.ReadDirectory() == sfFTPLib.enumError.ftpErrorSuccess)
{


FTPDirectory ftpDirectory = ftp.Directory;
ftp.ChangeDirectory(ftpDir);
Console.WriteLine(ftp.WorkingDirectory);

foreach(FTPItem objItem in ftpDirectory)
{
if (Convert.ToString(objItem.Type) == "ftpItemTypeFolder")
{
cgdirectories(objItem.Name);
}
}

}
else
{
if(err == sfFTPLib.enumError.ftpErrorLicense)
System.Console.WriteLine("Please acquire a license from http://www.smartftp.com");
else
System.Console.WriteLine("Connect() failed. LastError = {0}", ftp.LastError);
}
}
}

#2 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 15 November 2005 - 09:55 PM

Hello ..

1. You are opening a new connection for each call to cgdirectories()

2. You call the ChangeDirectory() function with the name of directory. You have to supply the full absolut path to the new directory.
e.g. "/blbaal/test" instead of "test"

-Mat




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users