Problem for list folder with goftp

Hey

I try to list the libs folder located on root of ftp server for that i do

files, err := sc.ReadDir("/libs")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to list remote dir: %v\n", err)
		return err
	}

But when i do that i have

Unexpected response: 501-No such directory.

I use “GitHub - secsy/goftp: FTP client for golang” lib.

I have tried to do “/libs” “libs” “libs/” “/libs” but not work

Can you help me?

Do you have a idea why i got this error?

I’m not sure about your setup, but this is probably because you don’t just have access to the filesystem on the target server. So let’s say the FTP server is set up to serve content from /var/ftp-files or something. When you ReadDir /libs it’s going to look for /var/ftp-files/libs on that server. I mean - you obviously wouldn’t want ftp clients to have access to your entire filesystem right? Anyway, it could be any number of things but this is my best guess.

Yes but in this case how I can get a folder located at root of ftp server but not at root of Linux server. (The folder is located in /home/user/ but ftp user can acess only /home/user/ he can t see /)

I would try logging in with a FTP client and checking to see if you can access that folder as a troubleshooting step. I think your code should work as long as that is a valid directory that the client has access to.

The theory is to either use relative pathes to navigate the hirarchy, or to ask the server for a PWD after connection and construct absolute pathes from that.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.