none
FTP OpenFile method syntax help

    Question

  • I know how to upload and download files to FTP but somehow im stuck with syntax how to just open a file in FTP server? Or I need to donwload the file, open it and an event when the file is closed so I can delete it from temorary directorty. In this method, im stuck with closed event...

    please help...

    Sunday, April 11, 2010 6:57 PM

Answers

  • Hi GaiusBaltar,

    If you want to delete the file after the file is closed, you can add a Exited event to the Process, and in the event, you can delete that file.
    Something likes the follows:
    Code-behind

    string filename ="my.exe";

    System.Diagnostics.Process myProcess =new System.Diagnostics.Process();

    myProcess.StartInfo.FileName = filename;

    myProcess.StartInfo.CreateNoWindow =true;

    myProcess.EnableRaisingEvents =true;

    myProcess.Exited +=new EventHandler(myProcess_Exited);

    myProcess.Start();

    myProcess.WaitForExit(0);


    void myProcess_Exited(object sender,EventArgs e)

    {

       //todo:delete the file here

    }

     

    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Monday, April 19, 2010 1:03 AM
    Thursday, April 15, 2010 3:35 AM

All replies

  • This might help:

    http://www.codeproject.com/KB/IP/FtpClient.aspx


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Monday, April 12, 2010 12:22 AM
  • No, that link did not help, it contained the information I allready know. I need to know how to just open a file from FTP. What I have now is that I download the file to TEMP directory and open it with System.Diagnistics.Process.Start(file). But I need the event when the file is closed so I can delete the file from the TEMP dir...
    Monday, April 12, 2010 7:10 AM
  • Either you explained badly or I understood you badly.

    Either way, that has nothing to do with FTP. You can't have a message indicating that another application stopped unless that application provides an API for that matter. You have to keep the Process Id and use Process.GetProcessById() periodically to see if the application is still open. If not, you can delete your temporary file.
    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Monday, April 12, 2010 8:53 AM
  • Salve Gaius (I can't just say "hi", sorry ;-),

    I think you misunderstand something - you simply cannot execute something "on the FTP server" - you'll always have to download whatever it is you want to execute. That being said, once you have downloaded the file, google/bing for i.e. "C# ShellWait" if you want your app to wait for the process to finish.


    Cheers,
    Olaf
    http://blogs.intuidev.com
    Monday, April 12, 2010 6:26 PM
  • Just did a little search in my forums-solution - here's an extended version of what I posted in this thread , now including a notification for the time when the OSK-process has been finished:

    <Window x:Class="WpfTests.OSK"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="OSK"
        SizeToContent="WidthAndHeight">
       <Button x:Name="cmdToggle" Content="Start/Stop" Click="cmdToggle_Click" Margin="2" Padding="3"/>
    </Window>
    
    Code-behind:
    using System.Windows;
    using System.Xml;
    using System.Diagnostics;
    
    namespace WpfTests
    {
       public partial class OSK : Window
       {
          public OSK()
          {
             InitializeComponent();
          }
    
          private Process _p = null;
          private void cmdToggle_Click(object sender, RoutedEventArgs e)
          {
             if (_p == null)
             {
                ProcessStartInfo pi = new ProcessStartInfo("osk.exe");
                _p = Process.Start(pi);
                _p.EnableRaisingEvents = true;
                _p.Exited += new System.EventHandler(_p_Exited);
             }
             else if (_p != null)
             {
                _p.Kill();
                _p.Dispose();
                _p = null;
             }
          }
    
          void _p_Exited(object sender, System.EventArgs e)
          {
             MessageBox.Show("OSK was just finished.");
             _p.Dispose();
             _p = null;
          }
       }
    }
    

    Cheers,
    Olaf
    http://blogs.intuidev.com
    • Edited by Olaf Rabbachin Monday, April 12, 2010 6:41 PM formatting ...
    • Proposed as answer by Olaf Rabbachin Saturday, April 17, 2010 12:25 PM
    Monday, April 12, 2010 6:39 PM
  • Hi GaiusBaltar,

    If you want to delete the file after the file is closed, you can add a Exited event to the Process, and in the event, you can delete that file.
    Something likes the follows:
    Code-behind

    string filename ="my.exe";

    System.Diagnostics.Process myProcess =new System.Diagnostics.Process();

    myProcess.StartInfo.FileName = filename;

    myProcess.StartInfo.CreateNoWindow =true;

    myProcess.EnableRaisingEvents =true;

    myProcess.Exited +=new EventHandler(myProcess_Exited);

    myProcess.Start();

    myProcess.WaitForExit(0);


    void myProcess_Exited(object sender,EventArgs e)

    {

       //todo:delete the file here

    }

     

    Hope this helps.

    Best regards,
    Linda Liu


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Monday, April 19, 2010 1:03 AM
    Thursday, April 15, 2010 3:35 AM
  • Any updates?

    Cheers,
    Olaf
    http://blogs.intuidev.com
    Thursday, April 15, 2010 8:40 AM