kedarkhetia
kedarkhetia

Reputation: 101

Error "no such directory" pyftpdlib

I have created an FTP server using python. I want to keep file to share at run time for which I am using raw_input() function but gives error "no such directory"

Any help is appreciated !

pasting my code below

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)

Upvotes: 1

Views: 590

Answers (1)

elitasson
elitasson

Reputation: 113

The variable c is simply not a directory that exists on your computer. This can be verified by the following:

in the top insert:

import sys

after

c = raw_input("path of file_to_transfer : ")

insert

if not os.path.isdir(c):
   print("%c is not a directory, exiting..." % (c))
   sys.exit()

Upvotes: 1

Related Questions