-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftptest.py
More file actions
executable file
·84 lines (70 loc) · 1.63 KB
/
Copy pathftptest.py
File metadata and controls
executable file
·84 lines (70 loc) · 1.63 KB
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
#!/usr/bin/python
from getpass import getpass
import ftplib, socket, sys
actionslist = ('put', 'get', 'rm', 'cd', 'ls')
success = 0
while not success:
try:
site = None
while not site:
site = raw_input('connect to: ').strip()
ftp = ftplib.FTP(site)
except socket.gaierror:
print 'server doesn\'t exist - try again'
else:
success = 1
success = 0
while not success:
try:
user = raw_input('user: ')
pswd = getpass('pswd: ')
ftp.login(user, pswd)
except ftplib.error_perm:
print 'user/password incorrect'
else:
success = 1
action = ''
while 1:
success = 0
while action.lower() not in actionslist:
action = raw_input('put file, get file, cd, quit? ').strip()
if action.lower() == 'quit': break
if action.lower() == 'get':
ftp.dir()
while not success:
try:
file = raw_input('get which file? ').strip()
ftp.retrbinary('RETR %s' % file, sys.stdout.write)
except ftplib.error_perm:
print 'file doesn\'t exist - try again'
else:
print
success = 1
if action.lower() == 'ls':
ftp.dir()
if action.lower() == 'put':
import os
counter = 0
for i in os.listdir('.'):
if i[0] != '.':
if counter == 1:
print '%-40s' % i
else:
print '%-40s' % i,
counter = not counter
if counter: print
while not success:
try:
file = raw_input('open which file?').strip()
localfile = open(file, 'rb')
ftp.storbinary('STOR %s' % file, localfile)
except IOError:
print 'file doesn\'t exist - try again'
except ftplib.error_perm:
print 'you do not have proper permissions'
break
else:
success = 1
action = ''
ftp.close()
print 'success'