Eric Bryan

Eric Bryan

  • NA
  • 18
  • 7.6k

Problem with Ftp commands inside a C# Web application

Jun 15 2014 12:35 PM

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 :

<code>  

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

</code> 

Ftp file ftp_cmd.txt :

<code> 

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

</code> 

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

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();
        }

</code> 


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

<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

</code>  


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.

 


Answers (2)