Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Hello.
I want to copy a file in my network environment. Username course against the system (server) has a password.
How do I perform this operation.
The following example has been implemented but will "Incorrect Function" error.
Please help me.

But I am getting this exception.
There are currently no logon servers available to service the logon request.






private void button3_Click(object sender, EventArgs e)
  {
   try
   {

    string _tempServerPath = Txt_ServerPath.Text + "\\" + Path.GetFileName(Txt_LocalPath.Text);
    if (!File.Exists(_tempServerPath))
    {
     AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
     WindowsIdentity idnt = new WindowsIdentity(Txt_User.Text, Txt_Pass.Text);
     WindowsImpersonationContext context = idnt.Impersonate();
     File.Copy(Txt_LocalPath.Text, _tempServerPath);
     context.Undo();
    }
    else
    {
     MessageBox.Show("specified file exists",
      "Error",
      MessageBoxButtons.OK,
      MessageBoxIcon.Error);
    }

   }
   catch (Exception _ex)
   {
    MessageBox.Show("Message :" + _ex.Message + Environment.NewLine +
     "Source :" + _ex.Source + Environment.NewLine +
     "Data :" + _ex.Data,
     "Error",
     MessageBoxButtons.OK,
     MessageBoxIcon.Error);
   }
  }


View Image Software and Exception:
http://www.ir-win.net/images/Pic_Question_CoptFile.jpg


But I am getting this exception.
There are currently no logon servers available to service the logon request.
Posted
Updated 26-Apr-11 4:52am
v4
Comments
Groulien 26-Apr-11 8:54am    
Which exact line threw the exception and what kind of an exception was it?
Ir-win ChakadCo 26-Apr-11 10:55am    
But I am getting this exception.
There are currently no logon servers available to service the logon request.

View Image Software and Exception:
http://www.ir-win.net/images/Pic_Question_CoptFile.jpg

1 solution

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
Rajesh Anuhya 28-Apr-11 6:53am    
Post the link, don't do Copy /paste

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