Error using FTP mget function - File not found on server
Show older comments
Hello everyone!
I've tried to use the mget function to get a file from a FTP server. It results in an error message that indicates that the file doesn't exist, but the file does exist. In fact, if I use the function delete with the same file name, it works properly, see the image below:

Furthermore, if I use mget(ftpobj,"*.txt"), it works and gets all the txt files, but if I use mget(ftpobj,"filename.txt") it does not work. I've also tried the mput function and it works well.
Has anyone experience this issue? Does anyone have a solution?
I've tried to see where the error is produced. Using the debugger in mget function, I've found that it calls the dir function in line 39:
[dirStruct, folderOrFile] = dir(obj, str);
This line outputs an empty dirStruct and folderOrFile = -1, which I guess it means a not found file.
But the problem is that if I open the dir function, I see that the second input argument is not a file name, but a folder name:
function varargout = dir(obj, folderName, options)
In fact, dir(obj) lists correctly the content.
Could it be the cause of the problem?
I appreciate any help to solve this problem.
4 Comments
Steven Lord
on 6 Mar 2026 at 20:43
What do you see displayed when you ask MATLAB to show the raw output? Show at least the line containing the file that caused mget to throw the error and maybe one or two lines containing other files in that same folder (for comparison purposes).
files = dir(ftpobj, "ParseOutput", false)
The reason I'm asking is because I wonder if there's something odd going on with the permissions for that file, while the files variable created by the above line of code may show. Maybe you have write permissions to it (which I think would allow you to delete it) but not read permissions?
Walter Roberson
on 6 Mar 2026 at 22:16
Permission to delete a file requires write permission to the directory, but ignores permission on the files itself (unless there is an Access Control List established on the file.)
Permission to get the file requires read permission on the file itself.
Juan
about 2 hours ago
Juan
about 1 hour ago
Answers (1)
It would seem to be an issue if the internal dir function isn't returning the specific file, agreed. However, it seems peculiar if there's an issue in creating the arguments to be passed inside the mget function that it works with the wildcard string. From a debugging standpoint, it would be interesting and perhaps useful to see what are the specific values of those arguments for the two cases.
However, unless one were to create a local copy of the mget function and make a user-aliased version to make any code corrections, the present workaround solution would be to wrap the present function into a mymget.m file and have it return the full list and then select the one specific file wanted to return inside it.
I don't suppose you have an earlier release installed that you could test whether this is a newly-introduced issue with R2025x? The example in the doc seems to work here for either form...
s = ftp('ftp.ngdc.noaa.gov')
dir(s)
mget(s,'*.txt')
mget(s,'INDEX.txt')
ver
What OS/platform are you on?
Submit this to Mathworks as an official support request/bug at <Product Support Page>
4 Comments
Juan
about 4 hours ago
dpb
about 4 hours ago
From your above note it doesn't appear the idea of permissions is the culprit so I think still wilt take Mathworks intervention here, but " it would be interesting and perhaps useful to see what are the specific values of those arguments for the two cases." in the prior debugging sessions you ran just to see what is different going into the dir() function call between the two cases. It seems really strange symptoms to me without seeing just what is getting passed into the routine.
Juan
about 3 hours ago
OK, thanks for the clarification...the workaround isn't to pass a wildcard in the file name but after the file name so it looks like a directory search instead of a file search...I hadn't caught out the difference and didn't see why '*test*.txt" would produce a different result that "test.txt".
As noted before, you could if wanted make a fixup in a local copy and alias the builtin or the less invasive workaround would be to write the wrapper function that adds the wildcard and then selects and returns the wanted file -- this moves the fixup to a lower level out of the main code although it isn't that much extra so is just a personal preference as to which way to go.
Seems strange such would have slipped through testing; the test suite must not be complete.
Categories
Find more on FTP File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!