- URL encoding: Before passing the directory name to the FTP commands, you can URL encode the name. This involves replacing the space in the directory name with its URL-encoded representation, which is "%20". For example, "/Base 1" would become "/Base%201". This encoding ensures that the FTP server interprets the directory name correctly.
- Connection handling: It's possible that the error you encountered is due to a lost connection. To handle this situation, you can wrap your FTP operations inside a try-catch block. In case of a connection failure, you can reconnect to the FTP server and then proceed with fetching the file. It's important to close the connection properly and reconnect when failures occur to ensure a stable connection.
Can't download data from FTP server with mget.
19 views (last 30 days)
Show older comments
Hello,
I am trying to connect to my FTP server and download data from an directory called "/Base 1". If I change the directory name in my FTP server to "/Base_1" and call that name instead, everything works as expected. The problem is that I must be able to use the name "/Base 1" with the spacing.
I tried to call dir(ftpobj) after the cd and everything looks correct. I am able to path into my directory in my FTP server with the files that I want to download. But when I try to use either dir( ftpobj,new_files(i)) or by commenting out the for loop and just call
mget(ftpobj,new_files(3))
which is a file that I know exists in my FTP server, I get an error that it does not exist.
Does anyone know how to solve this?
if exist('new_files','var')
new_files=rmmissing(new_files);
ftpobj = ftp(host,user,password);
cd(ftpobj,"/Base 1");
for i=1:length(new_files)
if ~isempty(dir(ftpobj,new_files(i)))
mget(ftpobj,new_files(i))
end
end
disp("The following files has been added to Base-1 directory: ")
disp(new_files)
end
0 Comments
Answers (1)
Chetan
on 28 Sep 2023
I understand that you are encountering difficulties when using the “mget” command to download files over FTP.
The issue you are facing could be related to how the FTP server handles directory names with spaces. Some FTP servers may not handle spaces in directory names correctly, resulting in problems when accessing or downloading files from those directories.
To address this issue, you can try the following approaches:
I hope these suggestions help you resolve the issue you are facing
0 Comments
See Also
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!