Hi,
I have a app where I need send a file by FTP. My SmartPhone is a Palm Treo Pro with Windows Mobile 6.1 Professional.
I have a problem: How to detect and create a 3G/GPRS connection ?
When I try execute this code, it don't connect/create/estabilished a connection with the FTP Server:
ftp = ftplib.FTP("ftp.myserver.com.br")
ftp.login("userName", "password")
ftp.set_pasv(0)
ftp.set_debuglevel(2)
ftp.sendcmd("CWD /public_ftp/incoming")
upload(ftp, myFile)
To solve this I have that open the "Internet Explorer" before execute my app and this is bad.
How to solve this problem ?
Thanks Leandro.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
# 20100705154437 # Manfred Schulte-Oversohl :: Pragmatis GmbH# Windows Mobile GPRS Connectionfromctypesimport*importtimeimportsysfromsocketimport*# Let's map the Microsoft types to ctypes for clarityBYTE=c_ubyteWORD=c_ushortDWORD=c_ulongclassGUID(Structure):_fields_=[("Data1",DWORD),("Data2",WORD),("Data3",WORD),("Data4",BYTE*8)]def__init__(self,name=None):ifnameisnotNone:oledll.ole32.CLSIDFromString(unicode(name),byref(self))def__str__(self):s=(c_wchar*39)()oledll.ole32.StringFromGUID2(byref(self),s,39)returns.valueclassConnectionInfo(Structure):_fields_=[("cbSize",c_uint),("dwParams",c_uint),("dwFlags",c_uint),("dwPriority",c_uint),("bExclusive",c_int),("bDisabled",c_int),("guidDestNet",GUID),("hWnd",c_void_p),("uMsg",c_uint),("lParam",c_uint),("ulMaxCost",c_uint),("ulMinRcvBw",c_uint),("ulMaxConnLatency",c_uint),]S_OK=0CONNMGR_PARAM_GUIDDESTNET=0x1CONNMGR_FLAG_PROXY_HTTP=0x1CONNMGR_PRIORITY_USERINTERACTIVE=0x08000INFINITE=0xffffffffCONNMGR_STATUS_CONNECTED=0x10ht={}cellcore=cdll.cellcoredefSetup(urlStr):ci=ConnectionInfo()phConnection=c_void_p()status=c_int()ifurlStrinht:returnTruedest=GUID()ret=cellcore.ConnMgrMapURL(unicode(urlStr),byref(dest),0)writeLog_File("GUID of dest: %s"%str(dest))ifret!=S_OK:returnFalseci.cbSize=sizeof(ci);ci.dwParams=CONNMGR_PARAM_GUIDDESTNETci.dwFlags=CONNMGR_FLAG_PROXY_HTTPci.dwPriority=CONNMGR_PRIORITY_USERINTERACTIVEci.guidDestNet=destci.bExclusive=0ci.bDisabled=0ci.hWnd=Noneci.uMsg=0ci.lParam=0ifcellcore.ConnMgrEstablishConnectionSync(byref(ci),byref(phConnection),INFINITE,byref(status))!=S_OKandstatus!=CONNMGR_STATUS_CONNECTED:returnFalsewriteLog_File("L087 ConnMgrEstablishConnectionSync True")ht[urlStr]=phConnectionwriteLog_File("len (ht) %s"%str(len(ht)))returnTruedefDoTcpConnection():''' With VPN setting firstly the Internet Connection via ISP will be established and then the VPN connection will be initialized '''url="asus"# dummy, name triggers VPN with settings for Work##url = "www.company.com" # for Internet via ISP##res = Setup("http://www.name.com/") # Internet Pattern##res = Setup("http://name/") # Work Pattern (without Dots)res=Setup("http://%s"%url)ifres:writeLog_File("connected to %s"%url)# Begin Sockets=socket(AF_INET,SOCK_STREAM)s.connect(('192.168.0.48',8000))# IP / Port of Destination PC in Work via VPNs.settimeout(5)s.send('Hello world via VNP')data=s.recv(1024)s.close()# End SocketwriteLog_File('Received: >%s<'%str(data))else:writeLog_File("Connection establishment failed")defwriteLog_File(log_txt='',log_file='',debug=0):ifnotlog_file:ifsys.argv[0].endswith(".py"):log_file=sys.argv[0].replace('.py','.log')else:log_file="%s.log"%sys.argv[0]iflog_file!='':fhnd=open(log_file,'a')fhnd.write("%s\t"%str(time.strftime('%Y%m%dT%H%M%S.',time.localtime())+str(time.time()).split('.')[1]))iflog_txt!='':fhnd.write("%s\n"%(log_txt))iflog_txt=='':fhnd.write("\n")fhnd.close()if__name__=="__main__":DoTcpConnection()
Enjoy
Manfred
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have a app where I need send a file by FTP. My SmartPhone is a Palm Treo Pro with Windows Mobile 6.1 Professional.
I have a problem: How to detect and create a 3G/GPRS connection ?
When I try execute this code, it don't connect/create/estabilished a connection with the FTP Server:
ftp = ftplib.FTP("ftp.myserver.com.br")
ftp.login("userName", "password")
ftp.set_pasv(0)
ftp.set_debuglevel(2)
ftp.sendcmd("CWD /public_ftp/incoming")
upload(ftp, myFile)
To solve this I have that open the "Internet Explorer" before execute my app and this is bad.
How to solve this problem ?
Thanks Leandro.
Here is the Code that works for me:
Enjoy
Manfred
Manfred,
I'll test your code !.
Thank you so much for your replay.
-Leandro