Error downloading .txt or .nc files through the ftp link
이전 댓글 표시
By using the following function;
>> ftpobj = ftp('ftp://nrt.cmems-du.eu/Core/INSITU_GLO_NRT_OBSERVATIONS_013_030/glo_multiparameter_nrt/index_monthly.txt',username,password,'System','UNIX')
I am encountering with the error message, I reaaly appreciate any help.
Error using connect (line 18)
Could not open a connection to "ftp", port "NaN".
Error in ftp (line 75)
connect(h)
Thanks
댓글 수: 1
Geoff Hayes
2020년 1월 8일
Farshid - please see ftp host input parameter to get an idea of how the host should be constructed. You seem to be passing a link to a file rather than the name of the FTP server (with or without the port).
답변 (2개)
Andrew Janke
2020년 1월 31일
Geoff is right. You're passing a URL to ftp(), when it only accepts host names. You need to do the directory navigation and file selection in a separate step once you're connected. Try this:
remote_dir = 'Core/INSITU_GLO_NRT_OBSERVATIONS_013_030/glo_multiparameter_nrt';
remote_file = 'index_monthly.txt';
f = ftp('nrt.cmems-du.eu',username,password);
cd(f, remote_dir)
mget(f, remote_file)
댓글 수: 7
Farshid Daryabor
2020년 2월 3일
Andrew Janke
2020년 2월 3일
FTP Error 500 is a "syntax error: command unrecognized". I don't know why it would be doing that; sorry.
Try doing the download manually with ncftp or another command-line ftp client to make sure things are working with other tools, too.
Andrew Janke
2020년 2월 3일
Any chance you could share a login to this ftp site so we could run your code and try to reproduce the error?
Farshid Daryabor
2020년 2월 3일
편집: Geoff Hayes
2020년 2월 3일
Andrew Janke
2020년 2월 3일
What version of Matlab are you running? Your example code fails for me in Matlab R2016b and R2017b, but works in R2018b and R2019b. (On macOS.) (Oddly, I looked at the source for ftp/mget and I don't really see what it's doing different between R2017b and R2018b. And I'm pretty sure it's using the same version of Apache Commons FTP.) You could upgrade to Matlab R2018b and maybe it'll work. Or you could try my alternative jl.net.ftp.FtpClient class: https://github.com/apjanke/janklab/blob/master/Mcode/classes/%2Bjl/%2Bnet/%2Bftp/FtpClient.m.
Farshid Daryabor
2020년 2월 3일
Geoff Hayes
2020년 2월 3일
Farshid - I modified your above comment to remove the host, username, and password from the code. I strongly recommend that you don't post such information on a public forum.
Farshid Daryabor
2020년 2월 3일
0 개 추천
댓글 수: 6
Andrew Janke
2020년 2월 3일
If you want to try my FtpClient out, download the whole Janklab library and add that to the path. Instructions are at https://github.com/apjanke/janklab#installation-and-use.
Might be easier for you to just upgrade Matlab. What version are you running? Do you have a current license?
Farshid Daryabor
2020년 2월 3일
Andrew Janke
2020년 2월 3일
Ah. You're out of luck then; Janklab requires R2017b or later.
Here's the example code for future reference in case you're able to upgrade to R2017b or later some time. Or you could just take my FtpClient.m code (and the other classes in the +jl/+net/+ftp package) and modify them to run in R2016b outside Janklab; they're not using that much code from the rest of the library.
addpath ~/local/repos/janklab/Mcode/toplevel/
init_janklab
remote_dir = 'Core/INSITU_GLO_NRT_OBSERVATIONS_013_030/glo_multiparameter_nrt';
remote_file = 'index_monthly.txt';
f = jl.net.ftp.FtpClient('nrt.cmems-du.eu');
f.username = my_username;
f.password = my_password;
f.connect;
f.cd(remote_dir);
f.mget(remote_file);
Andrew Janke
2020년 2월 3일
You know what, my FtpClient isn't working with that server either. It's also getting error 500 reply codes. I don't know what's going on there. I'll try turning on some protocol level logging to see what's going on.
Andrew Janke
2020년 2월 3일
Aha: You need to use Passive Mode. (Which is the whole reason I wrote that FtpClient in the first place.)
f = jl.net.ftp.FtpClient('nrt.cmems-du.eu', [], my_username, my_password);
f.connect;
f.pasv;
f.cd(remote_dir);
f.mget(remote_file);
Farshid Daryabor
2020년 2월 4일
카테고리
도움말 센터 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!