Problem with Ftp commands inside Web application

eric.bryan

Member
Joined
Jun 15, 2014
Messages
8
Programming Experience
3-5
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 :

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

C#:
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 :

C#:
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 :

C#:
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.
 

eric.bryan

Member
Joined
Jun 15, 2014
Messages
8
Programming Experience
3-5
Thank you for your reply jmcilhinney.

I tried what you said but it still doesn't work.

As I have a firewall error, do you have an idea about what application I should exclude (by creating a rule in the firewall) ?

I tried to exclude 'ftp.exe', 'w3wp.exe' but it's the same.

Eric.
 
Top Bottom