Error downloading .txt or .nc files through the ftp link

7 次查看(过去 30 天)
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
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
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
Farshid Daryabor 2020-2-3
could you show me example to run?
f = jl.net.ftp.FtpClient('Core/INSITU_GLO_NRT_OBSERVATIONS_013_030/glo_multiparameter_nrt')
Undefined variable "jl" or class "jl.net.ftp.FtpClient".
Geoff Hayes
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
Farshid Daryabor 2020-2-3
what do you mean? You mean to add "Ftp Client.m" to the path and run it?
  6 个评论
Andrew Janke
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
Farshid Daryabor 2020-2-4
Dear Andrew,
I'm really sorry for the delay in feedback. I actually added "class" and "toplevel" packages to the path. However, I did find some imbalance errors in "FtpClient" which I cleaned some of, but in the list below some errors have confused me to clear. Could you please tell me how I can fix it, thanks in advance.
% Remote host to connect to
host (1,1) string = string(missing)
% Port for the command port
port (1,1) double = NaN
% Username to log in as. Defaults to 'anonymous'.
username (1,1) string = 'anonymous'
% Password to provide. Defaults to your email address from Matlab's
% Internet prefs
password string = repmat('', [0 0])
% Account to use in addition to username and password. May be empty to
% indicate "no account"
account string = repmat('', [0 0])
end
properties(Dependent)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by