ashkulz / NppFTP

Plugin for Notepad++ allowing FTP, FTPS, FTPES and SFTP communications
https://ashkulz.github.io/NppFTP/
320 stars 93 forks source link

"Change Directory" button mishandles absolute paths #190

Open Ben-Voris opened 6 years ago

Ben-Voris commented 6 years ago

Description of the Issue

The "Change Directory" button mishandles absolute paths

Steps to Reproduce the Issue

  1. Connect to host where the default directory is not the root directory (e.g. is, /home/username)
  2. Click the Change Directory button
  3. Enter an absolute path that you have access to, e.g., "/tmp"

Expected Behavior

The files in the absolute path should be displayed

Actual Behavior

Nothing. In particular, no error messages.

Debug Information

Notepad++ v7.5.1 (32-bit) Build time : Aug 29 2017 - 02:35:41 Path : C:\Program Files (x86)\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : ComparePlugin.dll DSpellCheck.dll Explorer.dll gtagfornplus.dll HTMLTag_unicode.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppColumnSort.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll PluginManager.dll

NppFTP version 0.27.1 Unicode

A workaround is to change to root "/" and then change to the directory. Using appropriate .. doesn't work. For example, starting at /home/username, entering "../../tmp" doesn't work. Based on the code in FTPSession::GetDirectoryHierarchy(const char *), I don't expect relative paths to work.

I'm ignorant of Windows programming, but it seems the problem might be in FTPSession::GetDirectoryHierarchy(const char *). If nothing else, it's not handling a path that starts with "/" as a special case. Also, some invocations of the define OutMsg would be helpful.

Ben-Voris commented 6 years ago

It appeared to me that the FTP code might do more verbose logging than the SFTP code, so I found a host that supports FTP. There, a cd to the valid directory /tmp/dir1/dir2/dir3 puts nothing in the NppFTP Output window (Wireshark shows that nothing goes on the line). But a cd to "/" shows CWD /. After that, a cd to "/tmp/dir1/dir2/dir3" shows:

-> CWD /tmp/  
-> CWD /tmp/dir1/  
-> CWD /tmp/dir1/dir2/  
-> CWD /tmp/dir1/dir2/dir3  

I've updated to:

Notepad++ v7.5.4 (32-bit) Build time : Jan 1 2018 - 01:47:45 Path : C:\Program Files (x86)\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : ComparePlugin.dll DSpellCheck.dll Explorer.dll gtagfornplus.dll HTMLTag_unicode.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppColumnSort.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll PluginManager.dll

NppFTP version 0.27.3 Unicode

After the login, the Output window gets:

-> TYPE A  
200 Type set to A.
-> MODE S  
200 MODE S ok.
-> STRU F  
200 STRU F ok.
-> PWD  
257 "/home/bvoris" is current directory.
Connected
-> CWD /home/bvoris  
250 CWD command successful.
-> PORT 10,226,12,22,122,252  
200 PORT command successful.
-> LIST  
150 Opening data connection for /bin/ls (10.226.12.22,31484d) (0 bytes).
226 Transfer Complete.

Again, when I attempt to cd /tmp/dir1/dir2/dir3 nothing is logged. A cd to "/" gives:

-> CWD /  
250 CWD command successful.
-> PORT 10,226,12,22,122,253  
250 CWD command successful.
-> LIST  
200 PORT command successful.
150 Opening data connection for /bin/ls (10.226.12.22,31485d) (0 bytes).
226 Transfer Complete.

Then, a cd to /tmp/dir1/dir2/dir3 gives:

-> CWD /tmp/  
250 CWD command successful.
-> PORT 10,226,12,22,122,254  
200 PORT command successful.
-> LIST  
150 Opening data connection for /bin/ls (10.226.12.22,31486d) (0 bytes).
226 Transfer Complete.
-> CWD /tmp/dir1/  
250 CWD command successful.
-> PORT 10,226,12,22,122,255  
200 PORT command successful.
-> LIST  
150 Opening data connection for /bin/ls (10.226.12.22,31487d) (0 bytes).
226 Transfer Complete.
-> CWD /tmp/dir1/dir2/  
250 CWD command successful.
-> PORT 10,226,12,22,123,0  
200 PORT command successful.
-> LIST  
150 Opening data connection for /bin/ls (10.226.12.22,31488d) (0 bytes).
226 Transfer Complete.
-> CWD /tmp/dir1/dir2/dir3  
250 CWD command successful.
-> PORT 10,226,12,22,123,1  
200 PORT command successful.
-> LIST  
150 Opening data connection for /bin/ls (10.226.12.22,31489d) (0 bytes).
226 Transfer Complete.

In case it matters, /tmp contains a few hundred files. dir1 only contains dir2, dir2 only contains dir3, and dir3 contains one file. The connection is through a VPN and then some unknown number of routers and firewalls.