Page 1 of 1

FTP upload blocked by Firewall

Posted: Wed Feb 04, 2015 11:19 pm
by codemaker
I know that we can add a program to Firewall list and then this program can use FTP to upload the file. Otherwise it cannot.

I have a problem because if the Firewall block the program to do a FTP, it doesn't always show the screen which informs the user about the block and even offer to automatically insert the program to the Firewall list. Sometimes just hangs and then the user don't know what to do, oftenly they can only force the application close... Which is not elegant way of programmatically communication with user.

If I add the program into the Firewall list, then there is no problem of FTP uploading at all. Works perfect...

I am using FTTP class and I narrowed down the moment when the program should be presented by Firewall information if the program is not on the firewall list:
It hangs on:

// This creates the object normaly
oFile = TFtpFile():New( aTarget[ n ], oFTP )

// It hangs on the line below:
oFile:OpenWrite()
It doesn't show any info, just hangs forewer...

Is there any way I can catch the moment the Firewall is blocking opening the file for writting on FTP?
I tried

Code: Select all

TRY
   h := oFile:OpenWrite() 
CATCH
   alert("791 Cannot Open FTP file for write")
END
 
But this solution doesn't work. The program still hangs on the line which tries to openwrite() It never goes under the CATCH section.. :(
I need to drop to the line after CATCH to inform the user


The problem is that many times the users are not skilled even to find control panel and Firewall entry.
Also, sometimes the system doesn't allow them to add the program into the Firewall because they don't have administrator rights
And now I have problem that there is no at least some brief info for user what to do, the program just hangs... So the user ends up by staring ino the hanged application screen

Any idea here?

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 9:26 am
by Enrico Maria Giordano
Boris,

if your users want to drive a car they must get a drive license, right? So what's the difference? If your users want to communicate they must set their system correctly. :-)

EMG

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 11:54 am
by codemaker
Enrico,

I agree absolutely....
What I want is to cut off the number of calls and technical support calls from our clients.
The number of people who don't know how to deal with Firewall and practically nothing except the program they use on their everyday job - is huge :(
This is the reason I am trying to give them "ready made" solution whenever I can, otherwise I will have much more technical support calls...
(once one client asked me "where is my backup?", after I told her I have no idea because she decides where she will backup her files, she said "you are programmer, you should know"....)

Seems that the :OpenWrite function cannot be CATCH-ed, because it is not actually an error - the FTP class just tries to create and get the handle of the file on FTP server. Being blocked by Firewall seems is not considered as error.... :(

I was thinking to check in Firewall if the current program is already in Firewall exemptions list.
In such case, I might warn the client BEFORE the program stars the upload process...
Anyone know is it possible?

One strange thing.
First time I start the FTP upload program option and the program is not on the Firewall exemptions list, the Secure dialog pops up with the information the program should be added to Firewall exemptions and I can exit the program normaly. Next time the dialog doesn't pop up, the program just hangs....

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 12:08 pm
by Enrico Maria Giordano
Boris,
codemaker wrote:(once one client asked me "where is my backup?", after I told her I have no idea because she decides where she will backup her files, she said "you are programmer, you should know"....)
I know... :-(

I bet she doesn't ask her mechanic where she parked her car... :-(

EMG

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 12:54 pm
by hmpaquito
On 5/12/14 me emailed to Antonio L.:
Hola Antonio,

He hecho un pequeño metodo para la clase TFtp.prg. Consiste en poner un timeout a la conexion. Lo he probado una vez y parece que funciona. La llamada al metodo se ha de hacer despues de abrir la conexion de internet (InternetOpen()) y siempre que se quiera cambiar el timeout. Hay mas opciones que se pueden setear... yo de momento necesitaba solo el timeout.

Mi idea era que lo añadieses a Fivewin como tu creas conveniente.

Un cordial saludo

Code: Select all

//----------------------------------------------------------------------------//
// En WInInet.prg
DLL32 FUNCTION InternetSetOption( hFile AS LONG, nOption AS DWORD,;
                                  @cBuffer AS LPSTR, lSize AS LONG) ;
                                  AS BOOL PASCAL ;
                                  FROM "InternetSetOptionA" ;
                                  LIB hWinINet;



//-------------------------------------------------------------------------//
// En TFtp.prg
METHOD lSetTimeOutReceive(nSecTimeOut)
Local lOk
Local cTimeOut
Local nMiliSecTimeOut:= nSecTimeOut* 1000


#define INTERNET_OPTION_RECEIVE_TIMEOUT         6

cTimeOut:= LTrim(Str(nMiliSecTimeOut, 10, 0))

lOk:= InternetSetOption(::oInternet:hSession, INTERNET_OPTION_RECEIVE_TIMEOUT,;
                      @cTimeOut, 4)

RETURN lOk

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 5:13 pm
by codemaker
hmpaquito,

Can you please tell me, what exactly is the purpose of this method?
Can I use it somehow to catch the problem I have in function oFile:OpenWrite() when uploading to FTP?

If so, can you please make a small example

I need to be able either to detect if the program is in the Firewall list of exemptions and/or to be able to prevent OpenWrite() function to hangs the program forewer if the program is blocked by Firewall

Thanks

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 5:31 pm
by Otto
Hello Boris,
this is a powershell script I use to register a program.
Maybe this helps
Best regards,
Otto

Code: Select all

clear screen
#List all current Rule Groups
$rules=Get-NetFirewallRule
$DisplayGroups=foreach ($rule in $rules){$rule.displaygroup}
$DisplayGroups|Select-Object -Unique

#New-NetFirewallRule -DisplayName "art2test" -Direction Outbound -Program "C:\wh\art2test.exe" -Action Allow
#Delete a Rule
Remove-NetfirewallRule -DisplayName "art2test"

#netsh advfirewall firewall show rule name=all

netsh advfirewall firewall add rule name="atestbuchen" dir=in action=allow program="C:\wh_3\atestob.exe" enable=yes profile=private,domain

#netsh advfirewall export "C:\temp\WFconfiguration.wfw"  

 

Re: FTP upload blocked by Firewall

Posted: Thu Feb 05, 2015 6:50 pm
by codemaker
yes, I also find this by googling, but I am using this which does the job:

netsh firewall add allowedprogram C:\folder1\folder2\someprogram.exe myprog ENABLE

It enters the program in Firewall and I can upload. For now, because it is questionable if it works on all Windows OS.. :(

Re: FTP upload blocked by Firewall

Posted: Mon Feb 09, 2015 8:54 am
by dbmanfwh
Hi,
Job to differ in Windows os.

Code: Select all

FUNCTION Fire_Wall()
     LOCAL  cFile := CurDrive()+":\"+GetCurDir()+"\"+cFileName( GetModuleFileName( GetInstance() ) )

        IF isWin7() // .OR. isWin8() .OR. isWin10() 
           WinExec( "netsh advfirewall firewall delete rule name=MyProg dir=in" )
           SysWait(1)
           WinExec( "netsh advfirewall firewall add rule name=MyProg dir=in action=allow program="+cFile+" enable=yes profile=any" )
        ELSE
           WinExec("netsh firewall delete allowedprogram program="+cFile )
           SysWait(1)
           WinExec("netsh firewall add allowedprogram program="+cFile+" name=MyProg mode=enable scope=all" )
        ENDIF
RETURN NIL