Take the 2-minute tour ×

I am working on a project where images are taken by my android phone and are stored in folders in my SD card. I am working on a python script that needs to periodically move the folders from the SD to a particular folder in my PC. The phone and the PC are connected over the mobile Hotspot and I will be running a http server in the mobile. Previously I used to have script that sent the images in the form of email attachments to my gmail address but now i want to send the entire folder to my PC i donot want to use the internet. Can I do this? I would appreciate any kind of help with this.

Let me make my self more clear. I already have my own created httpServer python code running on the phone that is handling html pages run by an android application. I need to connect to that mobile server from my PC, I need to go to a folder named 'sb' in the sd card the path is /mnt/sdcard/sb there I need to find all the folders containing the alphabet 'd' and move those folders completely from the mobile to a directory in my PC.

Browsing various pages all I find is connecting to a server and getting HTML pages or simple files from there but I couldn't find anything that told me how to get folders and store it at a particular location. I really need this work done before 29th. I need to deliver the product on 31st January. Please do give me some good help.

share|improve this question
some please help me. –  Ryan Jan 28 '13 at 18:24
@phoenixyz can you please help me with this... –  Ryan Jan 29 '13 at 6:13

3 Answers 3

up vote 0 down vote accepted

Use the socket programming. Here is the code you can send files easily using it.


import os   
import sys,time 
import socket

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("", port))

client_socket, address = server_socket.accept()
print "Conencted to - ",address,"\n"

while (files):
    print '\nMaybe, pending work'
    for au in files:
        if (au.find('d')>-1):
            imgFiles = os.listdir(au)
            if (imgFiles[i].endswith('.jpg')):
                file_name = open(imgs,'rb')
                print file_name
                while True:
                    strng = file_name.read()
                    if not strng:  break        


import socket,os
import time

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("address", port))

#folder name
fp = open(filename,'wb')
# image
while True:
strng = client_socket.recv(1024)
print "4"
if not strng: break
print "5"
print "Data Received successfully"
share|improve this answer

Why use python for this ? Have you tried

wget --mirror http://your_android_device/folder_to_sync/
share|improve this answer
I actually need this code to be running at a regular interval of time and keep storing the folders on the PC. –  Ryan Jan 27 '13 at 16:56
Use a crontab to trigger wget at a given interval : man 5 crontab –  Julien Palard Jan 27 '13 at 17:02
I am sorry but i am not exactly aware of this could you provide me with a link where i can learn more about this. Thank you –  Ryan Jan 27 '13 at 17:12
Yeah, just open a terminal emulator, like xterm, and type "man 5 crontab", you will be presented with a great manual of what cron and crontabs can provide to you. –  Julien Palard Jan 27 '13 at 17:15
I am not getting it properly. i am not that acquainted wget i have just seen people work on in never worked on it myself could you tell me a proper guide to it. –  Ryan Jan 27 '13 at 17:37

You could use httplib. Something in the lines of:

import httplib

conn = httplib.HTTPConnection("http://device")
conn.request("GET", "/myfile.data")
resp = conn.getresponse()
data = resp.read()

See also the Python documentation of httplib.

share|improve this answer
Thank you I will give it a try –  Ryan Jan 27 '13 at 16:56
I am confused while mentioning the file object at the comm.request Once I connect to the mobile, I need to go to a folder named sb in the sd card the path is /mnt/sdcard/sb there I need to find all the folders containing the alphabet 'd' and move those folders completely from the mobile to a location in my PC. –  Ryan Jan 27 '13 at 17:45
caould you please help me with more detail?? I have added further description to the question. –  Ryan Jan 28 '13 at 12:45

Your Answer


