Error using FTP mget function - File not found on server

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 Commenti

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?
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.
Every file accessed individually triggers the error. However, when I use the wildcard * it works perfectly.
>> dir(ftpobj)
0000.TXT 10000.PNG 0001.TXT Series 10001.PNG 0002.TXT 10002.PNG
>> files = dir(ftpobj, "ParseOutput", false)
files =
7×1 string array
"03-09-26 10:31AM 45046599 0000.TXT"
"03-09-26 10:31AM 88073 10000.PNG"
"03-09-26 10:36AM 9010599 0001.TXT"
"03-04-26 04:14PM <DIR> Series"
"03-09-26 10:36AM 88165 10001.PNG"
"03-09-26 10:37AM 9010599 0002.TXT"
"03-09-26 10:37AM 88330 10002.PNG"
>> mget(ftpobj,"0000.TXT");
File "0000.TXT" not found on server.
>> mget(ftpobj,"0001.TXT");
File "0001.TXT" not found on server.
>> mget(ftpobj,"0002.TXT");
File "0002.TXT" not found on server.
>> mget(ftpobj,"10002.PNG");
File "10002.PNG" not found on server.
>> mget(ftpobj,"*.TXT"); % WORKS PERFECTLY
In addition, with a file uploaded using mput:
>> mput(ftpobj,"Test.TXT");
>> files = dir(ftpobj, "ParseOutput", false)
files =
8×1 string array
"03-09-26 10:31AM 45046599 0000.TXT"
"03-09-26 10:31AM 88073 10000.PNG"
"03-09-26 10:36AM 9010599 0001.TXT"
"03-04-26 04:14PM <DIR> Series"
"03-09-26 10:36AM 88165 10001.PNG"
"03-09-26 10:37AM 9010599 0002.TXT"
"03-09-26 10:37AM 88330 10002.PNG"
"03-09-26 10:43AM 9010599 Test.TXT"
>> mget(ftpobj,"Test.TXT");
File "Test.TXT" not found on server.
I would like to add that I can download any file individually using FileZilla client, so I guess it's not because of permissions.

Accedi per commentare.

Risposte (1)

dpb
dpb il 6 Mar 2026 alle 16:34
Spostato: dpb il 6 Mar 2026 alle 17:51
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')
FTP with properties: Host: "ftp.ngdc.noaa.gov" Username: "anonymous" Port: 21 ServerLocale: "en_US" DirParserFcn: @matlab.io.ftp.parseDirListingForUnix Mode: "binary" TLSMode: "none" LocalDataConnectionMethod: "passive" RemoteWorkingDirectory: "/" ConnectionTimeout: 5 min TransferTimeout: Inf min CertificateFilename: "default"
dir(s)
DMSP STP coastwatch geomag international pub INDEX.txt Snow_Ice dmsp4alan google12c4c939d7b90761.html ionosonde wdc README.txt Solid_Earth ftp.html index.html mgg
mget(s,'*.txt')
ans = 2×1 cell array
{'/users/mss.system.7r2dt/INDEX.txt' } {'/users/mss.system.7r2dt/README.txt'}
mget(s,'INDEX.txt')
ans = 1×1 cell array
{'/users/mss.system.7r2dt/INDEX.txt'}
ver
------------------------------------------------------------------------------------------------- MATLAB Version: 25.2.0.3150157 (R2025b) Update 4 MATLAB License Number: 40912989 Operating System: Linux 6.8.0-1024-aws #26~22.04.1-Ubuntu SMP Wed Feb 19 06:54:57 UTC 2025 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ------------------------------------------------------------------------------------------------- MATLAB Version 25.2 (R2025b) Simulink Version 25.2 (R2025b) 5G Toolbox Version 25.2 (R2025b) Aerospace Blockset Version 25.2 (R2025b) Aerospace Toolbox Version 25.2 (R2025b) Antenna Toolbox Version 25.2 (R2025b) Audio Toolbox Version 25.2 (R2025b) Automated Driving Toolbox Version 25.2 (R2025b) Bioinformatics Toolbox Version 25.2 (R2025b) Bluetooth Toolbox Version 25.2 (R2025b) Communications Toolbox Version 25.2 (R2025b) Computer Vision Toolbox Version 25.2 (R2025b) Control System Toolbox Version 25.2 (R2025b) Curve Fitting Toolbox Version 25.2 (R2025b) DO Qualification Kit Version 25.2 (R2025b) DSP System Toolbox Version 25.2 (R2025b) Database Toolbox Version 25.2 (R2025b) Datafeed Toolbox Version 25.2 (R2025b) Deep Learning Toolbox Version 25.2 (R2025b) Econometrics Toolbox Version 25.2 (R2025b) Embedded Coder Version 25.2 (R2025b) Financial Instruments Toolbox Version 25.2 (R2025b) Financial Toolbox Version 25.2 (R2025b) Fixed-Point Designer Version 25.2 (R2025b) Fuzzy Logic Toolbox Version 25.2 (R2025b) Global Optimization Toolbox Version 25.2 (R2025b) HDL Coder Version 25.2 (R2025b) HDL Verifier Version 25.2 (R2025b) IEC Certification Kit Version 25.2 (R2025b) Image Acquisition Toolbox Version 25.2 (R2025b) Image Processing Toolbox Version 25.2 (R2025b) Industrial Communication Toolbox Version 25.2 (R2025b) Instrument Control Toolbox Version 25.2 (R2025b) LTE Toolbox Version 25.2 (R2025b) MATLAB Coder Version 25.2 (R2025b) MATLAB Compiler Version 25.2 (R2025b) MATLAB Compiler SDK Version 25.2 (R2025b) MATLAB Report Generator Version 25.2 (R2025b) Mapping Toolbox Version 25.2 (R2025b) Medical Imaging Toolbox Version 25.2 (R2025b) Mixed-Signal Blockset Version 25.2 (R2025b) Model Predictive Control Toolbox Version 25.2 (R2025b) Model-Based Calibration Toolbox Version 25.2 (R2025b) Navigation Toolbox Version 25.2 (R2025b) Optimization Toolbox Version 25.2 (R2025b) Parallel Computing Toolbox Version 25.2 (R2025b) Partial Differential Equation Toolbox Version 25.2 (R2025b) Phased Array System Toolbox Version 25.2 (R2025b) Powertrain Blockset Version 25.2 (R2025b) Predictive Maintenance Toolbox Version 25.2 (R2025b) RF Blockset Version 25.2 (R2025b) RF Toolbox Version 25.2 (R2025b) Radar Toolbox Version 25.2 (R2025b) Requirements Toolbox Version 25.2 (R2025b) Risk Management Toolbox Version 25.2 (R2025b) Robotics System Toolbox Version 25.2 (R2025b) Robust Control Toolbox Version 25.2 (R2025b) Sensor Fusion and Tracking Toolbox Version 25.2 (R2025b) SerDes Toolbox Version 25.2 (R2025b) Signal Processing Toolbox Version 25.2 (R2025b) SimBiology Version 25.2 (R2025b) SimEvents Version 25.2 (R2025b) Simscape Version 25.2 (R2025b) Simscape Driveline Version 25.2 (R2025b) Simscape Electrical Version 25.2 (R2025b) Simscape Fluids Version 25.2 (R2025b) Simscape Multibody Version 25.2 (R2025b) Simulink 3D Animation Version 25.2 (R2025b) Simulink Check Version 25.2 (R2025b) Simulink Code Inspector Version 25.2 (R2025b) Simulink Coder Version 25.2 (R2025b) Simulink Control Design Version 25.2 (R2025b) Simulink Coverage Version 25.2 (R2025b) Simulink Design Optimization Version 25.2 (R2025b) Simulink Design Verifier Version 25.2 (R2025b) Simulink Desktop Real-Time Version 25.2 (R2025b) Simulink PLC Coder Version 25.2 (R2025b) Simulink Real-Time Version 25.2 (R2025b) Simulink Report Generator Version 25.2 (R2025b) Simulink Test Version 25.2 (R2025b) Stateflow Version 25.2 (R2025b) Statistics and Machine Learning Toolbox Version 25.2 (R2025b) Symbolic Math Toolbox Version 25.2 (R2025b) System Identification Toolbox Version 25.2 (R2025b) Text Analytics Toolbox Version 25.2 (R2025b) Vehicle Dynamics Blockset Version 25.2 (R2025b) Vehicle Network Toolbox Version 25.2 (R2025b) Vision HDL Toolbox Version 25.2 (R2025b) WLAN Toolbox Version 25.2 (R2025b) Wavelet Toolbox Version 25.2 (R2025b) Wireless HDL Toolbox Version 25.2 (R2025b)
What OS/platform are you on?
Submit this to Mathworks as an official support request/bug at <Product Support Page>

4 Commenti

I'm running it on Windows 10 Pro (version 22H2, 19045.6456).
My Matlab version is:
---------------------------------------------------------------------
MATLAB Version: 25.2.0.3055257 (R2025b) Update 2
MATLAB License Number: 41046929
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 19045)
Java Version: Java is not loaded
---------------------------------------------------------------------
MATLAB Version 25.2 (R2025b)
Simulink Version 25.2 (R2025b)
Control System Toolbox Version 25.2 (R2025b)
Signal Processing Toolbox Version 25.2 (R2025b)
Simscape Version 25.2 (R2025b)
Simscape Electrical Version 25.2 (R2025b)
I don't have any other Matlab version to check the performance of this function.
I'll submit it to Mathworks official support, thanks for the help.
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.
If you open the mget function, you will realize that the arguments going into the dir function (line 39) are the same inputs as in the mget (see partial code below).
function location = mget(obj, str, targetDirectory)
[dirStruct, folderOrFile] = dir(obj, str); % line 39
end
Inside the dir function, the callDirWithOptions function is called. In this case, the arguments are again the same initial ones, but note that folderName is the string of the file name ("0000.TXT" for example).
function varargout = dir(obj, folderName, options)
[listing, fileFoundAt] = callDirWithOptions(obj, folderName, namesOnly); % line 44
end
Something is wrong. In fact, Mathworks has confirmed me the bug:
"You might have run into a known issue in “mget” in R2025b.
To workaround the issue please try adding a wildcard after the filename and see if that resolves your issue."
And they are right, I can avoid the bug with:
mget(ftpobj,"0000.TXT*");
dpb
dpb circa 4 ore fa
Modificato: dpb circa 3 ore fa
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.

Accedi per commentare.

Prodotti

Release

R2025b

Tag

Richiesto:

il 6 Mar 2026 alle 11:50

Modificato:

dpb
circa 3 ore fa

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by