I'd like to be able to transfer files between my mobile phone and computer. The phone is a smartphone that can run python 2.5.4 and the computer is running windows xp (with python 2.5.4 and 3.1.1).
I'd like to have a simple python program on the phone that can send files to the computer and get files from the computer. The phone end should only run when invoked, the computer end can be a server, although preferably something that does not use a lot of resources. The phone end should be able to figure out what's in the relevant directory on the computer.
At the moment I'm getting files from computer to phone by running windows web server on the computer (ugh) and a script with socket.set_ default _ access_point (so the program can pick my router's ssid or other transport) and urlretrieve (to get the files) on the phone. I'm sending files the other way by email using smtplib.
Suggestions would be appreciated, whether a general idea, existing programs or anything in between.
Part 2: Transfer Files via Wifi-Direct After that, connect your PC to the same network. Launch the Feem application on your PC and Android devices. You will see them connected already once you open the application. Now, select your Android device and click on Send Files option.
The best way to transfer files between your PC and Android is to send them over a shared wireless network. You can use many apps for this, such as Wi-Fi File Transfer on Android and Air Transfer on iOS. Some file browsers also incorporate Wi-Fi file transfers.
I would use paramiko. It's secure fast and really simple. How bout this?
So we start by importing the module, and specifying the log file:
import paramiko
paramiko.util.log_to_file('/tmp/paramiko.log')
We open an SSH transport:
host = "example.com"
port = 22
transport = paramiko.Transport((host, port))
Next we want to authenticate. We can do this with a password:
password = "example101"
username = "warrior"
transport.connect(username = username, password = password)
Another way is to use an SSH key:
import os
privatekeyfile = os.path.expanduser('~/.ssh/id_rsa')
mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
username = 'warrior'
transport.connect(username = username, pkey = mykey)
Now we can start the SFTP client:
sftp = paramiko.SFTPClient.from_transport(transport)
Now lets pull a file across from the remote to the local system:
filepath = '/home/zeth/lenna.jpg'
localpath = '/home/zeth/lenna.jpg'
sftp.get(filepath, localpath)
Now lets go the other way:
filepath = '/home/zeth/lenna.jpg'
localpath = '/home/zeth/lenna.jpg'
sftp.put(filepath, localpath)
Lastly, we need to close the SFTP connection and the transport:
sftp.close()
transport.close()
How's that?? I have to give credit to this for the example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With