You are not logged in.

#1 2016-12-12 19:48:12

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Trouble to access Android FTP server

The file manager of my Android smartphone includes an ftp server. I can connect to this server and it includes a single directory: "Phone Storage". With commands line tools such as ftp or lftp, every time I try to cd to the directory, I get an error, as shown below:

[oesser@pcolivier ~]$ ftp 192.168.1.3 2121
Connected to 192.168.1.3.
220 SwiFTP 6.0.12.12 ready
Name (192.168.1.3:oesser): anonymous
331 Send password
Password: 
230 Access granted
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT OK
150 Opening ASCII mode data connection for file list
drwxr-xr-x 1 owner group         4096 Dec 11 17:34 Phone Storage
226 Data transmission OK
ftp> cd "Phone Storage"
550 Can't CWD to invalid directory
ftp> 

I try escaping the "Phone Directory" to  Phone\ Directory but I get the same error. I have similar errors with lftp.

However, if I try to access it with Thunar (putting

ftp://192.168.1.3:2121

in the address bar); everything works fine and I can browse the directories and transfer files as expected. Does anyone have a clue why the command line tools fail? Maybe the space in the initial directory?

Last edited by olive (2016-12-12 19:52:50)

Offline

#2 2016-12-13 10:30:24

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

Is it possible that your Folder has a trailing or leading space as well as one between the two words?

Check with ls if it has extra whitespace. You could also try cd *Phone* or something of that nature to see if you make it into the folder.

Last edited by bryan.paradis (2016-12-13 10:35:05)

Offline

#3 2016-12-13 11:54:11

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Trouble to access Android FTP server

@bryan.paradis. I see no such things and there is no weird spaces (apart from the middle one) when I access it when mounted with gvfs-mount (which works correctly). I tried to set ftp and lftp debug mode but I do not see anything interesting, it justs CWD to Phone storage and the answer is inevitably "Can't CWD to invalid directory". I do not know how to have a debug output of what gvfs-mount do.

Last edited by olive (2016-12-13 11:54:57)

Offline

#4 2016-12-13 12:10:43

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

Is the folder a symlink? Can you create another folder without a space and see if that works? Anywhere here is the code. Not much telling there. Could be some weird thing where it's not figuring out the path correctly.

http://www.programcreek.com/java-api-ex … mdCWD.java

 newDir = inputPathToChrootedFile(sessionThread.getWorkingDir(), param); 
---snip--- 
   try { 
    newDir = newDir.getCanonicalFile(); 
    if(!newDir.isDirectory()) { 
     sessionThread.writeString("550 Can't CWD to invalid directory\r\n"); 
    } else if(newDir.canRead()) { 
     sessionThread.setWorkingDir(newDir); 
     sessionThread.writeString("250 CWD successful\r\n"); 
    } else { 
     sessionThread.writeString("550 That path is inaccessible\r\n"); 
    } 

Last edited by bryan.paradis (2016-12-13 12:15:38)

Offline

#5 2016-12-13 15:19:55

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Trouble to access Android FTP server

@bryan.paradis. Here is what I have tried but I am not an Android specialist. First I can't create any directory in the root folder. But I think it is expected, I can't create it with the GUI of the file manager on the phone either. Probably the server itself has no permission to do so. I have installed an ssh server on my android phone (simplesshd) and log in to my phone with that. From what I see, the "Phone Storage" directory on the ftp server corresponds to "/storage/emulated/0" and I see no real "Phone Storage" directory, nor symlinks. I guess this is a virtual directory created by the ftp server. Note that I have no root access on the Phone , so that I can't see everything.

But gvfs-mount is able to handle all of this correctly. I can also enter the address in a Web browser and this work correctly. So I think it's a problem with the command line tools ftp and sftp that do something which is not correct. But I don't know why...

Last edited by olive (2016-12-13 16:28:53)

Offline

#6 2016-12-14 02:12:24

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

If you ask me if you are able to use Thunar they have worked around some sort of weird path that swiFTP gives back and the command line tools have no such workaround implemented. Try sniffing the ftp command packets on your computer to check the actual paths being sent around. Or maybe there is some sort of debug setting for ftp command line tools to show these kinds of things?

Can you post the debug log of ftp?

Can you check the logcat on your android phone as you try as well? Is there anything logged? Is there a swiftp logfile somewhere if not?

Last edited by bryan.paradis (2016-12-14 02:17:37)

Offline

#7 2016-12-14 03:18:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,796

Re: Trouble to access Android FTP server

Have you tried the -p option with ftp?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2016-12-14 07:19:07

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

ewaller wrote:

Have you tried the -p option with ftp?

if he is already able to ls the root I don't think it has to do with active vs passive? Looking at the code from swiftp it looks like some sort of canonicalpath problem?

Offline

#9 2016-12-14 09:15:46

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Trouble to access Android FTP server

I had already tried the "passive option", but without success.

Offline

#10 2016-12-14 09:39:48

bleach
Member
Registered: 2013-07-26
Posts: 264

Re: Trouble to access Android FTP server

i was wrong

Last edited by bleach (2016-12-14 09:43:11)

Offline

#11 2016-12-14 09:52:22

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Trouble to access Android FTP server

bryan.paradis wrote:

If you ask me if you are able to use Thunar they have worked around some sort of weird path that swiFTP gives back and the command line tools have no such workaround implemented. Try sniffing the ftp command packets on your computer to check the actual paths being sent around. Or maybe there is some sort of debug setting for ftp command line tools to show these kinds of things?

Can you post the debug log of ftp?

Can you check the logcat on your android phone as you try as well? Is there anything logged? Is there a swiftp logfile somewhere if not?

With lftp, I can have a full debug output; I post it below, but I do not see anything more. The logcat command on android does not give me further information. I do not find a swift debug on android but I have no root access on this phone and some files are hidden into directories with only access permission, so you can find them unless you know precisely where it is. Thunar uses in fact gvfs and I can use gvfs-mount instead (and I see the content under $XDG_RUNTIME_DIR/gvfs/<dir> (where <dir> depends of the address). It would be interesting to have a log of what gvfs do since it ois apparently able to handle it correctly. I have however no clues how to get it, if you know...

Full log of lftp:

[oesser@pcolivier ~]$ lftp -p 2121 192.168.1.3
ftp://192.168.1.3:2121> debug
ftp://192.168.1.3:2121> ls
---- Connecting to 192.168.1.3 (192.168.1.3) port 2121
<--- 220 SwiFTP 6.0.12.12 ready
---> FEAT
<--- 530 Login first with USER and PASS
---> USER anonymous
<--- 331 Send password
---> PASS lftp@
<--- 230 Access granted
---> FEAT
<--- 211-Features supported
<---  UTF8                          
<--- 211 End
---> PWD
<--- 257 "/"
---> OPTS UTF8 ON
<--- 502 Unrecognized option
---> PASV
<--- 227 Entering Passive Mode (192,168,1,3,235,235).
---- Connecting data socket to (192.168.1.3) port 60395
---- Data connection established
---> LIST -F
<--- 150 Opening ASCII mode data connection for file list
---- Got EOF on data connection
---- Closing data socket
drwxr-xr-x 1 owner group         4096 Dec 12 21:10 Phone Storage
<--- 226 Data transmission OK
ftp://192.168.1.3:2121/> cd "Phone Storage"
---- CWD path to be sent is `/Phone Storage'
---> CWD Phone Storage
<--- 550 Can't CWD to invalid directory       
cd: Access failed: 550 Can't CWD to invalid directory (/Phone Storage)
ftp://192.168.1.3:2121/> 

Offline

#12 2016-12-14 09:58:37

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

Can you sniff the Thunar ftp traffic and look at the path being sent with the CWD there?

Maybe there is a zero width space or some other weird character in the folder name. Thunar is only displaying the object with the path it is being given. In the command line tools you are typing the filename.

Last edited by bryan.paradis (2016-12-14 10:08:55)

Offline

#13 2016-12-14 10:38:49

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Trouble to access Android FTP server

OK, I have used tcpdump and I found the problem. gvfs (Thunar) send "CWD /Phone Storage" while ftp and lftp send "CWD Phone Storage" (note the relative path). I try to send the raw "CWD /Phone Storage" command with ftp (using the quote command):

quote "CWD /Phone Storage"

and it indeed works and cd into the directory and I can use ls after that to list Phone Storage. I don't know what are exactly the specification of ftp and who is to blame...

Last edited by olive (2016-12-14 10:45:16)

Offline

#14 2016-12-14 23:29:11

bryan.paradis
Member
Registered: 2016-10-22
Posts: 43

Re: Trouble to access Android FTP server

Well. I'd say Thunar's development included putting the current working directory path in front of the relative path returned by swiftp to work around ftp problems with relative paths.

If you make some further levels of folders and check how it behaves you may find either it is only a problem when / is the current working directory or with all relative paths. Most likely swiFTP quirks. The code is linked above if you are curious to take this further.

Offline

Board footer

Powered by FluxBB