forked from mattmc719/471proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellCmds.py
54 lines (42 loc) · 1.19 KB
/
shellCmds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Created on : 4-3-2018
# Created by: Erine Estrella
import socket
import os
import sys
from cmd import Cmd
class MyShell(Cmd):
def do_get(self, args):
print "Now downloading filename : %s from the server..." % filename
while True:
fileData = fileObj.read(65536)
#make sure we do not hit EOF
if fileData:
dataSize = str(len(fileData))
while len(dataSize)< 10:
dataSize = "0" + dataSize
fileData = dataSize + fileData
bytesSent = 0
while len(fileData) > BytesSent:
bytesSent += connSock.send(fileData[bytesSent:])
else:
break
print "Filname: " filename, " with size ", bytesSent, " has been downloaded."
connSock.close()
fileObj.close()
#def do_put(self, args):
#def do_ls (self, args):
def do_quit(self, args):
print "Now disconnecting from the server and quiting..."
raise SystemExit
if __name__ == '__main__':
shell = MyShell()
shell.prompt = 'ftp> '
shell.cmdloop('Starting Client...')
#server address
serverAddress = "ecs.fullerton.edu"
serverPort = 1234
fileName = sys.argv[1]
fileObj = open(fileName, "r")
connSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
bytesSent = 0
fileData = None