我使用python创建了一个FTP服务器。我想在运行时保持文件共享,我正在使用raw_input()函数,但给出错误“没有这样的目录”
任何帮助表示赞赏!
粘贴我的代码
import os
cmd = "apt-get install python-pyftpdlib"
a = os.popen(cmd).read()
import logging
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
def ftp_start(password,port,file_to_share):
cmd = "hostname -I"
a = os.popen(cmd).read()
b = a.split()
print "wlan0 : ",b[0]
cmd = "wget -qO- http://ipecho.net/plain"
a = os.popen(cmd).read()
print "Public Ip : ",a
cmd = "geoiplookup %s" %(a)
a = os.popen(cmd).read()
print a
cmd = "whoami"
username = os.popen(cmd).read()
length = len(username)
print "length = ",length
user = username[:length-1]
print "\n\n"
print "FTP IP :",b[0]
print "FTP ID :",user
print "FTP Password :",password
print "FTP Port :",port
if(port):
pass
else:
port = "8080"
authorizer = DummyAuthorizer()
authorizer.add_user(user, password, file_to_share, perm='elradfmwM')
handler = FTPHandler
handler.authorizer = authorizer
logging.basicConfig(filename='/var/log/pyftpd.log', level=logging.INFO)
server = FTPServer((b[0], port), handler)
server.serve_forever()
a = raw_input("password : ")
b = raw_input("port : ")
c = raw_input("path of file_to_transfer : ")
ftp_start(a,b,c)
答案 0 :(得分:1)
变量c
根本不是您计算机上存在的目录。这可以通过以下方式验证:
:
import sys
后
c = raw_input("path of file_to_transfer : ")
插入
if not os.path.isdir(c):
print("%c is not a directory, exiting..." % (c))
sys.exit()