In [29]:
import os

In [30]:
import os.path

In [31]:
import socket

In [32]:
serverSend = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

In [33]:
serverSend.bind(('fendesk', 22))


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-33-293bebb8a696> in <module>()
----> 1 serverSend.bind(('fendesk', 22))

/usr/lib64/python2.7/socket.pyc in meth(name, self, *args)
    222 
    223 def meth(name,self,*args):
--> 224     return getattr(self._sock,name)(*args)
    225 
    226 for _m in _socketmethods:

error: [Errno 99] Cannot assign requested address

In [34]:
import spur

In [35]:
shell = spur.LocalShell()

In [36]:
defDir = ('/home/wcmckee/Desktop/pybackupz')

In [37]:
import pyflakes

In [ ]:
socket.

In [11]:
os.chdir(defDir)

In [16]:
import spur

shell = spur.LocalShell()
result = shell.run(["echo", "-n", "hello"])
print result.output # prints hello


hello

In [17]:
desktopz = spur.SshShell(hostname="fendesk", username="will", password="comp123")
with desktopz:
    result = desktopz.run(['echo', '-n', 'hello'])
print result.output


---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
<ipython-input-17-87d7267a3750> in <module>()
      1 desktopz = spur.SshShell(hostname="fendesk", username="will", password="comp123")
      2 with desktopz:
----> 3     result = desktopz.run(['echo', '-n', 'hello'])
      4 print result.output

/usr/lib/python2.7/site-packages/spur/ssh.pyc in run(self, *args, **kwargs)
     68 
     69     def run(self, *args, **kwargs):
---> 70         return self.spawn(*args, **kwargs).wait_for_result()
     71 
     72     def spawn(self, command, *args, **kwargs):

/usr/lib/python2.7/site-packages/spur/ssh.pyc in spawn(self, command, *args, **kwargs)
     78         command_in_cwd = self._generate_run_command(command, *args, store_pid=store_pid, **kwargs)
     79         try:
---> 80             channel = self._get_ssh_transport().open_session()
     81         except EOFError as error:
     82             raise self._connection_error(error)

/usr/lib/python2.7/site-packages/spur/ssh.pyc in _get_ssh_transport(self)
    176             return self._connect_ssh().get_transport()
    177         except (socket.error, paramiko.SSHException, EOFError) as error:
--> 178             raise self._connection_error(error)
    179 
    180     def _connect_ssh(self):

ConnectionError: Error creating SSH connection
Original error: [Errno 113] No route to host

In [5]:
newpath = ('sftp://192.168.1.11/home/shared/webcam3')

In [6]:
os.chdir(newpath)


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-6-056693b12b6c> in <module>()
----> 1 os.chdir(newpath)

OSError: [Errno 2] No such file or directory: 'sftp://192.168.1.11/home/shared/webcam3'

In [314]:
filDir = ('/var/motion')
copyDir = ('/home/wcmckee/Documents')

In [315]:
os.chdir(filDir)

In [334]:


In [335]:
class Backup(object):
    def findfiles(self, filestring):
        filecur = os.listdir(os.curdir)
        for filename in filecur:
            if filestring in filename:
                yield filename

In [336]:
app = Backup()

In [337]:
app.findfiles('mp')


Out[337]:
<generator object findfiles at 0x2da6780>

In [366]:
year = ('2014')
month = ('01')
day = ('23')
hour = ('07')
mint = ('30')
secnd = ('20')

In [367]:
comboData = (year + month + day + hour + mint + secnd)

In [368]:
print comboData


20140123073020

In [369]:
for aviz in app.findfiles(comboData):
    print aviz

In [370]:
print aviz


20140123-timelapse.mpg

In [371]:
fixDir = filDir + '/' + aviz

In [372]:
import paramiko

In [373]:
sshNow = paramiko.SSHClient()

In [374]:
os.chdir('/home/wcmckee/Documents')

In [375]:
password = open('ps.txt', 'r')

In [376]:
thePass = password.readline()

In [393]:
sshNow.connect('192.168.1.4', username='wcmckee',password = thePass)


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-393-d92ea9f9639f> in <module>()
----> 1 sshNow.connect('192.168.1.4', username='wcmckee',password = thePass)

/usr/lib/python2.7/site-packages/paramiko/client.pyc in connect(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock)
    303                 except:
    304                     pass
--> 305             retry_on_signal(lambda: sock.connect(addr))
    306 
    307         t = self._transport = Transport(sock)

/usr/lib/python2.7/site-packages/paramiko/util.pyc in retry_on_signal(function)
    276     while True:
    277         try:
--> 278             return function()
    279         except EnvironmentError, e:
    280             if e.errno != errno.EINTR:

/usr/lib/python2.7/site-packages/paramiko/client.pyc in <lambda>()
    303                 except:
    304                     pass
--> 305             retry_on_signal(lambda: sock.connect(addr))
    306 
    307         t = self._transport = Transport(sock)

/usr/lib64/python2.7/socket.pyc in meth(name, self, *args)
    222 
    223 def meth(name,self,*args):
--> 224     return getattr(self._sock,name)(*args)
    225 
    226 for _m in _socketmethods:

error: [Errno 111] Connection refused

In [394]:
import shutil

In [395]:
copyMovz = shutil.copy2(fixDir, copyDir)

In [396]:
for fileza in app.findfiles('last'):
    print fileza

In [397]:
import time

In [398]:
from PIL import Image
from PIL import ImageDraw
from PIL import ImageChops
import random
import os
from PIL import ImageEnhance
from ftplib import FTP

In [399]:
ftp = FTP('ftp.freshfigure.com')
ftp.login('ipython', 'Testing123now#')


Out[399]:
'230 OK. Current restricted directory is /'

In [400]:
def upload(ftp, file):
    ext = os.path.splitext(file)[1]
    if ext in (".txt", ".htm", ".html", ".jpg", ".mpg"):
        ftp.storlines("STOR " + file, open(file))

In [401]:
upload(ftp, aviz)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-401-8126cb1d0103> in <module>()
----> 1 upload(ftp, aviz)

<ipython-input-400-7d90d3e4c130> in upload(ftp, file)
      2     ext = os.path.splitext(file)[1]
      3     if ext in (".txt", ".htm", ".html", ".jpg", ".mpg"):
----> 4         ftp.storlines("STOR " + file, open(file))

/usr/lib64/python2.7/ftplib.pyc in storlines(self, cmd, fp, callback)
    494             if callback: callback(buf)
    495         conn.close()
--> 496         return self.voidresp()
    497 
    498     def acct(self, password):

/usr/lib64/python2.7/ftplib.pyc in voidresp(self)
    222     def voidresp(self):
    223         """Expect a response beginning with '2'."""
--> 224         resp = self.getresp()
    225         if resp[:1] != '2':
    226             raise error_reply, resp

/usr/lib64/python2.7/ftplib.pyc in getresp(self)
    208     # Raise various errors if the response indicates an error
    209     def getresp(self):
--> 210         resp = self.getmultiline()
    211         if self.debugging: print '*resp*', self.sanitize(resp)
    212         self.lastresp = resp[:3]

/usr/lib64/python2.7/ftplib.pyc in getmultiline(self)
    194     # these are separated by '\n' characters in the string
    195     def getmultiline(self):
--> 196         line = self.getline()
    197         if line[3:4] == '-':
    198             code = line[:3]

/usr/lib64/python2.7/ftplib.pyc in getline(self)
    181     # Raise EOFError if the connection is closed
    182     def getline(self):
--> 183         line = self.file.readline()
    184         if self.debugging > 1:
    185             print '*get*', self.sanitize(line)

/usr/lib64/python2.7/socket.pyc in readline(self, size)
    445             while True:
    446                 try:
--> 447                     data = self._sock.recv(self._rbufsize)
    448                 except error, e:
    449                     if e.args[0] == EINTR:

KeyboardInterrupt: 

In [387]:
import shutil
import time
import PIL

In [388]:
copyFilez = shutil.copy2('/home/will/Documents/photoz/lastsnap.jpg', '/home/will/Downloads/photoz/lastsnap.jpg')


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-388-91fe5190025a> in <module>()
----> 1 copyFilez = shutil.copy2('/home/will/Documents/photoz/lastsnap.jpg', '/home/will/Downloads/photoz/lastsnap.jpg')

/usr/lib64/python2.7/shutil.pyc in copy2(src, dst)
    128     if os.path.isdir(dst):
    129         dst = os.path.join(dst, os.path.basename(src))
--> 130     copyfile(src, dst)
    131     copystat(src, dst)
    132 

/usr/lib64/python2.7/shutil.pyc in copyfile(src, dst)
     80                 raise SpecialFileError("`%s` is a named pipe" % fn)
     81 
---> 82     with open(src, 'rb') as fsrc:
     83         with open(dst, 'wb') as fdst:
     84             copyfileobj(fsrc, fdst)

IOError: [Errno 2] No such file or directory: '/home/will/Documents/photoz/lastsnap.jpg'

In [39]:
'''
for x in range(0, 3):
    time.sleep(20)
    copyFilez
    print('done!')

'''


Out[39]:
"\nfor x in range(0, 3):\n    time.sleep(20)\n    copyFilez\n    print('done!')\n\n"

In [40]:
savImz = PIL.Image.open(fileza)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-40-8788b2b0f718> in <module>()
----> 1 savImz = PIL.Image.open(fileza)

NameError: name 'fileza' is not defined

In [41]:
savImz.show()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-41-87e9e96f123e> in <module>()
----> 1 savImz.show()

NameError: name 'savImz' is not defined

In [41]:


In [ ]: