FTP upload blocked by Firewall

FTP upload blocked by Firewall

Postby codemaker » Wed Feb 04, 2015 11:19 pm

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  Expand view

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?
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: FTP upload blocked by Firewall

Postby Enrico Maria Giordano » Thu Feb 05, 2015 9:26 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: FTP upload blocked by Firewall

Postby codemaker » Thu Feb 05, 2015 11:54 am

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....
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: FTP upload blocked by Firewall

Postby Enrico Maria Giordano » Thu Feb 05, 2015 12:08 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: FTP upload blocked by Firewall

Postby hmpaquito » Thu Feb 05, 2015 12:54 pm

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  Expand view
//----------------------------------------------------------------------------//
// 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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: FTP upload blocked by Firewall

Postby codemaker » Thu Feb 05, 2015 5:13 pm

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
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: FTP upload blocked by Firewall

Postby Otto » Thu Feb 05, 2015 5:31 pm

Hello Boris,
this is a powershell script I use to register a program.
Maybe this helps
Best regards,
Otto

Code: Select all  Expand view

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"  

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6048
Joined: Fri Oct 07, 2005 7:07 pm

Re: FTP upload blocked by Firewall

Postby codemaker » Thu Feb 05, 2015 6:50 pm

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.. :(
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: FTP upload blocked by Firewall

Postby dbmanfwh » Mon Feb 09, 2015 8:54 am

Hi,
Job to differ in Windows os.

Code: Select all  Expand view

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
Regards,
Moon
FWH 16.11 | xHarbour | Harbour | BCC72 | DBF | ADS | MySQL | DrLib
dbmanfwh
 
Posts: 38
Joined: Tue Mar 04, 2008 3:44 pm
Location: Korea


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 48 guests