how to copy files from android to windows share using python? - android

Im trying to copy some files to and from a windows share. I am using python 2.7 and the pysmb library. This works fine with win7, but not with android. I build my connection over VPN with SMBConnection. listShares and listPath is working. Under win7 there is no problem using also os.path.isdir or shutil.copyfile. But that does not work with android. This is my code:
server_name = '192.168.168.12'
conn = SMBConnection(username=username, password=password, my_name='waldi2'
remote_name=server_name, domain=domain, use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED, is_direct_tcp=True)
connected = conn.connect(server_name, 445)
# obtain a list of shares:
Response = conn.listShares(timeout=30) # !!!working, shows e.g.(' Share[', 20, '] =', u'JBW_in')
os.path.isdir('//192.168.168.12/JBW_in/') # is False with android, True with win7 !??
shutil.copyfile('/sdcard/waldi2_0/data/stop.txt', '//192.168.168.12/JBW_in/stop.txt')
This is no prob with win7, but with android it throws:
[Errno 2] No such file or directory: '//192.168.168.12/JBW_in/stop.txt'
Any clues? would be very very welcome ....
Or maybe alternative approaches to manage some python-based file-exchange between android and windows-server.

If I understund you correctly you are trying to connect to an android device via SMB. By my knowledge android doesnt have support for SMB server natively, but you could install a third-party app with a SMB server.

Related

Direct connection to Firebird with IBDac/UniDac from Android using Delphi

I'm trying to connect to a REMOTE Firebird Database from Android using Delphi and IBDac. It says that cannot find libfbclient.so.3.0.2 library. I put it in the deploy to all library paths and nothing. If I remove the library it doesn't connect neither. The android version is 7.0. Thanks in advance.
my solution:
in delphi (deploying): add file libfbclient.so.3.0.2
remote-path: assets\internal
in delphi (program):
no entry in IBCConnection ClientLibrary
source code:
IBCConnection1.Server:= *server-ip or name*;
IBCConnection1.ClientLibrary:= TPath.Combine(TPath.GetDocumentsPath, 'libfbclient.so.3.0.2');
IBCConnection1.DataBase:= *datebase name*;
IBCConnection1.Connect;

Boost.Asio on Android failing with Service Not Found (Boost 1.53; NDK r8e)

I am trying to build a cross-platform application for Android and iOS and have chosen to use Boost to simplify communication and to parse the JSON from the response. Everything works fine in iOS, but Android fails with "service not found" error, or "host not found (authoritative)" if I change the query to query(server, "");.
I pulled the code out of my application and simplified it to what was throwing the error and this is what I have:
...
#include <boost/asio.hpp>
boost::asio::io_service io_service;
std::string server = "<server_address>";
// Get a list of endpoints corresponding to the server name.
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(server, "http");
boost::system::error_code ec;
boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query,ec);
if (ec)
{
return env->NewStringUTF(ec.message().c_str());
}
I am using Android NDK r8e (64-bit) and Boost version 1.53 (latest releases as of writing). I have used https://github.com/MysticTreeGames/Boost-for-Android with slight modification to work with the 64-bit NDK (see https://github.com/MysticTreeGames/Boost-for-Android/pull/28) for building the required Boost libraries.
I will be modifying this to work with async_resolve, which is what the iOS version is using, once I can get this part working.
Edit:
I noticed I had forgotten to update the Android Manifest file, so I added
<uses-permission android:name="android.permission.INTERNET"></uses-permission>, but I still get the same errors. Am I simply missing something else in the manifest?
It means that the OS can't figure out which port stands for http. On most POSIX-compliant systems this mapping is done in /etc/services file, and if http line is missing there, you'll get "service not found" error.
I don't know whether Android has this file or not (older versions didn't support it at all, the services were hardcoded in bionic), but if you get the above error, the only workaround is to set the desired port manually:
tcp::resolver::query query(tcp::v4(), yourHost, "80");

app won't recognize function in non-android jar

I am writing an app to connect to a database on a server (AS400 server using SQL to talk to the database). IBM supplies a java toolbox to access the server in a jar called jt400android.
I have a test function:
protected void ConnectionTest()
{
AS400 system = new AS400("jc400");
try
{
system.connectService(AS400.RECORDACCESS);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
AS400 is a function included in the jt400android.jar in com.ibm.as400.access.* that handles socket protocol, connections, and authentication to an AS400 machine. (I've resorted to this method as JDBC is apparently not a good way to go).
The code compiles just fine, no errors or warnings, but when I run the apk on my AVD, I get this error
03-12 22:44:30.300: E/dalvikvm(484): Could not find class 'com.ibm.as400.access.AS400', referenced from method jcpaper.android.jc400droid.MainActivity.ConnectionTest
I've searched the forums and tried the following suggestions:
added the jar to Java Build Path > Libraries (did this to make the code compile)
checked jar on Java Build Path > Order and Export
included a copy of the jar in [project folder]/libs
Each time I end up with the same could not find class error.
I'm running Eclipse for mobile (Juno v1) on Windows XP, building for Android 2.3.3.
Any suggestions on what's happening here?
The JTOpen Lite/JTLite libraries might provide a better way of connecting to your server. These libraries are new from IBM and are designed for specific use on Android devices.
JTOpen Lite - IBM Developer Works
JTOpen Lite Javadoc
Make sure that you add the .jar to the build path and export the libraries properly.
The record level access method that you are trying to use is an older method for connecting applications to DB2 databases, so you will probably have a harder time finding information about it.

Pusher not working on Phonegap for Android

I'm facing a problem and would really appreciate your help...
Android SDK: 4.0
Phonegap: 1.8.1
Pusher: 1.12
I have created an Android project using Phonegap that needs to receive server notifications through Pusher.
I'm running it in Eclipse and AVD emulator, but the problem is that every time I try to establish a connection to pusher, I get an Unavailable state from the bind to state_change.
I have tested the connection to Internet in the emulator browser and it works fine. I have also tested that the server is responding and that the Pusher key is the right one by testing my code on Firefox.
This are the steps I have followed:
I have included the WebSocket.java and WebSocketFactory.java files in the src folder.
I have included websocket.js file in my js folder and included a reference in the index.html file.
I have included a reference to http://js.pusher.com/1.12/pusher.js in the index file.
I have included the following line in my Android App.java file: this.appView.addJavascriptInterface(new WebSocketFactory(this), "WebSocketFactory");
This is the code I'm using to connect to Pusher:
// Connect
var pusher = new Pusher(CONFIG.PUSHER.APP_KEY);
pusher.connection.bind('state_change', connectionStateChange);
function connectionStateChange(state) {
alert(state.current);
}
Is there something I'm missing? Any ideas on why the connection is not working or about where to check?
Thanks for your help.
Chadid
For version 2.x of pusher-js and above the library will work within PhoneGap without any additional requirements or setup. Simply include the library and use it - no need for WebSocket.java or WebSocketFactory.java.
For version 1.x this blog post and associated code demonstrates how to get Pusher working on PhoneGap:
http://blog.pusher.com/2012/7/5/pusher-on-phonegap-for-android

Run python Script in android application

I want to get list of installed software on remote computer.For that I want to use python script in my android application.Now,I have a python script which is getting the list of installed software on remote computer.But,I don't know how to make it supported in android.
For this, I found SL4A android Scripting here . So, I tried to run my python script in android device using SL4A.But,It's not working and giving me error because some packages like win32.client is missing.I don't know more about SL4A so I don't know how to convert my python script in Android supported form.So,anyone have any idea or code please suggest me.....
Also If anyone have another way to get installed software list from remote Pc then please suggest...
Below is my python script
import wmi
from winreg import (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx)
c = wmi.WMI(computer="PC02",user="admin",password="a#1",namespace="root/default").StdRegProv
result, names = c.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")
print('These subkeys are found under "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"\n\n')
separator = "*" * 80
keyPath = r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
count = 0
while count < len(names):
try:
print(separator+'\n')
path = keyPath + "\\" + names[count]
key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
temp = QueryValueEx(key, 'DisplayName')
display = str(temp[0])
print (" Name: "+display+'\n',"key:",names[count])
count += 1
except:
print ("Key:",names[count])
count += 1
continue
Run the script on your remote computer, and expose the list of installed software on HTTP, a good way to write this simple web app is to use flask and its development server to serve the list of installed software, then write a python script which uses the native android web interface to fetch the list and display it.
You are having problems with missing libraries because you are importing windows specific ones. At any rate, this isn't the correct script to be running. This script seems to be for a computer, not an android phone.
You're trying to use a Python script that uses Windows Management Instrumentation (WMI), on a device that doesn't have that library.
Sadly, WMI on Python requires the win32 library, which is only available on Windows. I don't think you're going to have much success on checking the installed programs on remote Windows computer from an Android device in this way.
Since WMI is based on WBEM, you may be able to use wbem to access it; you might want to try using pywbem, a pure python wbem library.
Running python scripts is now achievable in gradle system using Tasks
task pythonFile(type:Exec) {
workingDir 'src_path'
commandLine 'python', 'my_script.py'
}

Categories

Resources