I am trying to retrieve a list of files from a remote FTP server using the ls command. When just executing ls by itself in the command line, it lists the files. When adding a filename to the command, it returns an empty file.
My code works perfectly on several other ftp servers (likely different server config). Not sure what is going wrong.
ftp> Packet tracing On .
ftp> trace on
Connected to ************.
OPEN ************
220 ************ FTP server ready.
User (*****************):
331 Password required for ********.
230 User ********* logged in. Access restrictions apply.
ftp> CD incoming
250 CWD command successful.
ftp> Local directory now C:\csrkb\etl\files\incoming\TASK0460\txt\FTP_OBJ_LIST.
ftp> LCD C:\csrkb\etl\files\incoming\TASK0460\txt\FTP_OBJ_LIST
ftp> ls - FTP_OBJECT_LIST.TXT
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.
ftp> BYE
221-You have transferred 0 bytes in 0 files.
221-Total traffic for this session was 12603 bytes in 2 transfers.
221-Thank you for using the FTP service on ftp-out.
221 Goodbye.
The ls and dir commands in ftp are intended to take a remote directory as a first parameter, not a filename - doing so with a filename may or may not work, depending on the ftp server. The syntax is:
Having a hyphen immediately after the 'ls' portion with something else following is not a valid command, so who knows what it will do. As is specifying a filename as the first parameter. It should only be a remote directory name.
Why are you using the dash after ls? The remote server is returning an empty list. I would search in the FTP server logs. Make also a network capture with Wireshark. If you have a L7 firewall you should do a capture on the server and compare the two captures.