Click here to Skip to main content
15,885,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm looking for a way to count files on an ftp server on Visual basic 2008/2010 :sigh: :((
Posted
Updated 28-Nov-10 11:50am
v2
Comments
JF2015 28-Nov-10 17:50pm    
Removed pre tags to improve readability.

Have you even bothered searching for this? I very much doubt it.

Because I'm in a good mood, this[^] might help you. It was one of the first hits on a search.

If you have searched, then I apologize, but if, as I suspect, you haven't, don't be so lazy next time.
 
Share this answer
 
Comments
fjdiewornncalwe 28-Apr-11 8:26am    
OPs answer moved where it needs to be:
Nice, But I'am not lazy because have searched about it but i didn't find any thing
And i want it for Visual basic not C#
Henry Minute 28-Apr-11 8:37am    
There are countless C# to VB converters out there. None are perfect but most of them will do most of the work for you. All that is required is a little application.
downloadDownload the source code -423 KB




Introduction:

Today I put a sample program to manage your FTP
Perhaps all of you with many programs to work with FTP or have seen much of you need to have transferred the file to the server or servers to receive and manage the server.
It can create folders, manage and delete files and folders, upload and download files to your will.


Familiar with the concept for "FTP" and the launch method, click here




To view original size Click on the photos.

Software_FTP
View_FTP


Background:
The software language is written in C # 2008.
I plan to have written part of office automation and felt that's too difficult to copy and upload in a network environment are fully software compatible with Windows Server - XP and 7 are by all FTP Microsoft and all FTP installed on the data center support.



Comment code:
1 - Uploading a file:



 private void Btn_UploadFTP_Click(object sender, EventArgs e)
{
   string _tempServerPath = Txt_ServerPath.Text + <br />           "\\" + Path.GetFileName(Txt_LocalPath_Upload.Text);
   ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
   ftPclient1.Upload(Txt_LocalPath_Upload.Text, _tempServerPath);
}
public bool Upload(FileInfo fi, [Optional, DefaultParameterValue("")] string targetFilename)
{
  string str;
  bool _Lvr=true;
  if (targetFilename.Trim() == "")
     {
       str = this.CurrentDirectory + fi.Name;
     }
  else if (targetFilename.Contains("/"))
     {
       str = this.AdjustDir(targetFilename);
     }
   else
      {
        str = this.CurrentDirectory + targetFilename;
      }
   string uRI = this.Hostname + str;
   FtpWebRequest request = this.GetRequest(uRI);
   request.Method = "STOR";
   request.UseBinary = true;
   request.ContentLength = fi.Length;
   byte[] array = new byte[0x800];
   using (FileStream stream = fi.OpenRead())
      {
       try
         {
          using (Stream stream2 = request.GetRequestStream())
            {
             int num;
               do
                {
                  num = stream.Read(array, 0, 0x800);
                  stream2.Write(array, 0, num);
                  Application.DoEvents();<br />                  CountProcesses = <br />                             Convert.ToInt32(<br />                             Math.Round((decimal)(stream.Position * 100) / stream.Length));
                  ChangePerocesses_Upload();
                 }
                while (num >= 0x800);
               stream2.Close();
              }
           }
           catch (Exception exception1)
            {
             _Lvr = false;
              ProjectData.SetProjectError(exception1);
              Exception exception = exception1;
              ProjectData.ClearProjectError();
             }
            finally
             {
               stream.Close();
             }
        }
   request = null;
   UploadComplite();
   return _Lvr;
}


2 - Download the file:

private void button4_Click(object sender, EventArgs e)
{
   string _Source_DownloadPath = Txt_ServerPath.Text + "\\" + Txt_FileNameDownload.Text;
   ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
   ftPclient1.Download(_Source_DownloadPath, Txt_LocalPath_Download.Text, false);
}





3 - Display files:

private void button5_Click(object sender, EventArgs e)
{
    Txt_View_FtpFile.Text = string.Empty; ;
    ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
    List<string> _listFile = ftPclient1.ListDirectory("//"+Txt_ServerPath.Text);
    for (int i = 0; i < _listFile.Count; i++)
     {
       Txt_View_FtpFile.Text += _listFile[i].ToString() + Environment.NewLine;
     }
}


 
Share this answer
 
Comments
Manfred Rudolf Bihy 28-Apr-11 13:40pm    
Please post this as a tip or as an article. OP's post is to far in the past so most people will not notice your solution. If you make it a tip or an article it will appear in the list of recently posted tips or articles and thus you'll have a much broader audience.
Please follow the guidelines on publishing information on CodeProject!

Thanks for your cooperation.
Manfred Rudolf Bihy 28-Apr-11 13:42pm    
Once you've decided what you to do please leave a "Reply" to my comment. I'll then come back to take appropriate measures.
Thank you again for your attention!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900