0
votes

The situation:

I'm trying to code a ftp file auto up and download program. It will iterate through my files and auto upload new files. The ftp server is build into my wifi router. I have included the ftp-server into my Ubuntu filesystem and everything work's fine (I can access everything). The home site is like family folders and my own folder.

Now my problem:

So far I was able to connect to the server and change into my directory and list the folders. But if I want to change from this directory into e.g. C++ (it's a folder inside my directory), I'll get an error message saying "Permission denied". The user account used to login is the same used in my file-system inclusion.

The python 3 code:

from ftplib import FTP_TLS


class ftp_client():

    def __init__(self, host, unandpw):
        self.host = host
        self.logindata = unandpw #should be a touple
        self.ftp = FTP_TLS(self.host)
        self.ftp.login(self.logindata[0], self.logindata[1])
        self.ftp.prot_p()

    def scan(self):
        self.ftp.cwd("/" + self.logindata[0] + "/")
        self.listoffiles = self.ftp.nlst()
        print("list of files: " + str(self.listoffiles))
        for file in self.listoffiles:
            self.ftp.cwd("/" + str(file) + "/")
            self.listoffilesinfiles = self.ftp.nlst()
            print(self.listoffilesinfiles)
            self.ftp.cwd("/" + self.logindata[0] + "/")

I'm calling it via an external main file...

The console output:

list of files: ['C++', 'Documents', 'Pictures', 'Python', 'School', 
'share', 'Videos']
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    ftp.scan()
  File "/home/simon/Python/autoserversync/client.py", line 18, in scan
    self.ftp.cwd("/" + str(file) + "/")
  File "/usr/lib/python3.5/ftplib.py", line 630, in cwd
    return self.voidcmd(cmd)
  File "/usr/lib/python3.5/ftplib.py", line 277, in voidcmd
    return self.voidresp()
  File "/usr/lib/python3.5/ftplib.py", line 250, in voidresp
    resp = self.getresp()
  File "/usr/lib/python3.5/ftplib.py", line 245, in getresp
    raise error_perm(resp)
ftplib.error_perm: 550 /C++/: Permission denied.

Now my question (obviously) is: how can I fix this?

1
Does this happen with directories named something other than 'C++'?pvg
@pvg Yes is does, I've tried several others...same resultSoloritur
Have you been able to write to these dirs with a regular ftp client? And more generally, if you have pretty much any other choice of protocol, use that instead of ftppvg
@pvg Yeah, I've used the webclient of my wifi router and I have integrated it into my file system and every thing works. What other protocols could I choose from, e.g. tcp?Soloritur
I'm not sure what is running where and connecting to what. But you can just scp things to your ubuntu box or tunnel over ssh to it and do whatever. ftp is an annoying and finicky bidirectional protocol that, if you can help it, should avoid.pvg

1 Answers

0
votes

In your self.ftp.cwd("/" + str(file) + "/") line, you're adding a slash to the start of your path. Remember that in Unix, a path starting with a slash is an absolute path, starting from the root directory.

If your folders are in your home directory instead (judging by their names I'm guessing they are) try changing it to self.ftp.cwd("~/" + str(file) + "/") instead.