locked
Problem with Ftp commands inside a C# web application RRS feed

  • Question

  • User-1668256174 posted

    Hello everybody,

    I have developped a web application which should upload files to a Ftp server.

    But I didn't succeed these uploads.

    I use a Ftp command file : Ftp_Upload.bat :

    ftp -n -i -s:"C:\Essai_Ftp\ftp_cmd.txt">"C:\Essai_Ftp\ftp.log"
    

    Ftp file ftp_cmd.txt :

    OPEN 100.100.100.100
    user usr_essai
    pwd_essai
    binary
    cd dir_essai
    mput "C:\Essai_Ftp\*.doc"
    quit
    

    Here is the C# code which calls the Ftp command file :

    public void Send_Ftp()
            {
    
                Process oProc = new Process();
    
                ProcessStartInfo oInfo = new ProcessStartInfo();
    
                string sFtpCommandFile = "c:\\Essai_Ftp\\Ftp_Upload.bat";
                oInfo.FileName = sFtpCommandFile;
                oInfo.UseShellExecute = false;
                oInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
                oProc.StartInfo = oInfo;
                oProc.Start();
                oProc.WaitForExit();
            }
    
    

    Here is the Ftp log file when I run the C# code :

    ftp> Connecté à 100.100.100.100
    OPEN 100.100.100.100
    220 ESSAI1
    ftp> user usr_essai
    331 User usr_essai, password please
    
    230 Password Ok, User logged in
    ftp> binary
    200 Type Binary
    ftp> cd dir_essai
    250 Change directory ok
    ftp> ftp> 
    mput "C:\Essai_Ftp\*.doc"
    200 Port command received
    425 Unable to open the data connection
    200 Port command received
    425 Unable to open the data connection
    200 Port command received
    425 Unable to open the data connection
    200 Port command received
    425 Unable to open the data connection
    ftp> ftp> 
    quit
    221 
    

    On the other hand, when I run this command file (Ftp_Upload.bat) manually, the files are correctly uploaded.

    And the code works correctly when I disable the Windows firewall (I am in Windows 7).

    But I cannot let the Windows firewall disabled for security reasons.

    Do you have an idea ?

    Thanks a lot in advance.

    Eric.

    Friday, June 13, 2014 9:05 AM

Answers

  • User-821857111 posted

    I don't know. This isn't really an ASP.NET question. You might find more help in a forum that covers Windows security.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 15, 2014 2:20 PM

All replies

  • User-821857111 posted

    Instead of trying to start processes on the web server, why not use the FtpWebRequest class?

    Ignore that. I see your issue is with the Firewall. You should be able to create an exception for FTP in the firewall. 

    Friday, June 13, 2014 9:11 AM
  • User-1668256174 posted

    Thank you for your answer Mikesdotnetting,

    I already have created rules in the Windows firewall for out going flow.

    I have created rules for programs : ftp.exe, w3wp.exe, but it's the same.

    What program should I except in the firewall ?

    Eric.

    Sunday, June 15, 2014 11:44 AM
  • User-821857111 posted

    I don't know. This isn't really an ASP.NET question. You might find more help in a forum that covers Windows security.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 15, 2014 2:20 PM
  • User-1925713106 posted

    Hi Eric, 

    Thanks for your post.  

    Please contact Windows 7 experts for the better response about Windows firewall. 

    Monday, June 16, 2014 4:54 AM
  • User-1668256174 posted

    Thank you for your advice Mikesdotnetting and George.

    Il will post a question in the Windows 7 forum.

    Eric.

    Tuesday, June 17, 2014 4:10 AM