-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
88 lines (78 loc) · 2.45 KB
/
client.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from ftplib import FTP
import glob
import os
import sys
import tnsorflow
import numpy as np
import pandas as pd
b=[1,2,3,4,5]
print b
ftp=FTP()
# setting connection with the server taking username and password as input from the user
def conn():
# connecting to server ip address
ftp.connect("localhost",8000)
# taking input from user
user=input("Username:")
passwrd=input("Password:")
# sending credentials for verification
ftp.login(user,passwrd)
# sending the server those files which are stared i.e. their name end with a star
def send(fname):
# going to the specified directory
os.chdir("/home/arindam/Desktop/c")
q=open(fname,"rb")
m=fname.replace("/home/arindam/Desktop/c/","")
print m
l="STOR "+m
# performing STOR command to upload file to server
ftp.storbinary(l,q)
# changing file names that have been uploaded by replacing * in their names
nf=m.replace("*","")
os.rename(m,nf)
#extractig paths of files in the directory and calling the send() function on them
def exfiles():
# finding all files in the specified directory
files=glob.glob("/home/arindam/Desktop/c/*.*")
# checking files with * at their end
for f in files:
print f
k=f.index(".")
ch=f[k-1]
if ch=='*':
send(f)
# this module is used to get command from the user
# some error handling applied more to be applied
def command():
com=input("command>>>")
if com=="upload":
exfiles()
command()
elif com=="exit":
print "---------------------------------------"
print " PROGRAM EXITED "
print "---------------------------------------"
exit()
else:
print "---------------------------------------"
print " UNKNOWN COMMAND PLEASE TRY AGAIN "
print "---------------------------------------"
command()
# This module provides the CLI to the user to interact with the user
def interface():
try:
conn()
except:
print "---------------------------------------"
print " ACCESS DENIED "
print "---------------------------------------"
interface()
print "---------------------------------------"
print " ACCESS GRANTED "
print "---------------------------------------"
command()
if __name__=="__main__":
k=0
print "initialise"
interface()
print("init_end")