Error using ftp/mget Read timed out

20 views (last 30 days)
Hello, I am downloading large satellite rainfall datasets from a NASA ftp and keep running into a timeout issue when using the function mget. This issue arises when I try to access one folder in particular. This folder takes around 1 minute to display its contents when I access it manually through a web browser, so I think the solution is to just increase the timeout for mget, which I do not know how to accomplish. Below is the the loop I use to download from the ftp along with the accompanying timeout error I get. Additionally I am using MATLAB R2015b. Thanks in advance
%%Code for downloading the Surface Temperature (gprof) and Radar Precipitation (dpr) data from the GPM Satellite
clc
clear
clear classes % Not sure why I need this but sometimes the code will not run without it.
% Initiate connection to the ftp server
username = 'xxxxxxxxxxx';
password = 'xxxxxxxxxxx';
ftpobj = ftp('arthurhou.pps.eosdis.nasa.gov',username,password);
pasv(ftpobj) % Allows passive mode FTP (https://www.mathworks.com/matlabcentral/fileexchange/6626-passive-mode-ftp-in-matlab)
% Set the timeframe of the data that needs to be collected
year= '2015';
month = {'02'};
for i=1:size(month,2)
day=dir(ftpobj,['/gpmdata/',year,'/',month{i}]); % to obtain numbers of days in that month
for k=1;
path_ftp = ['/gpmdata/',year,'/',month{i},'/',day(k).name];
path_env = '/radar/2A-ENV.GPM.DPR*.HDF5';
mget(ftpobj,[path_ftp,path_env],'C:\Users\sloan091\Documents\PhD\ExtremeRainfallAnalysis\Matlab\Brandon_Codes');
end
end
Error using ftp/mget (line 32)
Java exception occurred:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at org.apache.commons.net.ftp.FTPClient.listNames(FTPClient.java:1957)

Accepted Answer

Walter Roberson
Walter Roberson on 3 Sep 2017
hs = struct(ftpobj);
old_timeout = hs.jobject.getConnectTimeout; %if you want to query
hs.jobject.setConnectionTimeout(50); %or as appropriate
Note: you cannot access the jobject field of ftpobj directly: you must struct() it to bypass the type security.
  2 Comments
Brandon Sloan
Brandon Sloan on 4 Sep 2017
Thank you very much! That did the trick, I appreciate it
Ian Garrick-Bethell
Ian Garrick-Bethell on 2 Jan 2023
I get the following error when attempting this solution in Matlab 2022 for Windows:
"Unrecognized field name "jobject"."
Is there a new solution to setting the connection timeout time? Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!