{"id":6168,"date":"2015-09-04T09:09:18","date_gmt":"2015-09-04T13:09:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=6168"},"modified":"2015-09-02T20:09:35","modified_gmt":"2015-09-03T00:09:35","slug":"passive-mode-ftp","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2015\/09\/04\/passive-mode-ftp\/","title":{"rendered":"Passive Mode FTP"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/6626-passive-mode-ftp-in-matlab\">Passive Mode FTP in MATLAB<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869996\">Idin Motedayen<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n\r\n   <p>My pick this week comes from former guest blogger, Idin Motedayen-Aval. I spend a lot of my time interacting with MATLAB users\r\n      and showing examples of things you can do with the various MathWorks products.  After these mettings, we always like to make\r\n      the example available to everyone who attended so they can learn from the material.  We use FTP for this since the files tend\r\n      to be large.\r\n   <\/p>\r\n   <p>I used to use FileZilla for this but since it's the same process, a couple of years ago I automated it with MATLAB using a\r\n      little utility function called <tt>ftplink<\/tt>.  Here's the help for it:\r\n   <\/p><pre>   % Usage:\r\n   ftplink(name, file) - returns ftp link and uploads file to it\r\n   ftplink(name)       - returns ftp link\r\n   ftplink()           - returns home directory<\/pre><p>This function always worked great from MathWorks headquarters and from my house but not from hotels or many other public wireless\r\n      networks.  I just assumed it was a firewall blocking it until I shared this utility with my colleague, Adam, who pointed out\r\n      that I was not using passive mode in FTP - something new to me.  An explanation is <a href=\"http:\/\/slacksite.com\/other\/ftp.html\">here<\/a>.  He pointed me to Idin's submission and said if I used it, it would work.\r\n   <\/p>\r\n   <p>I like that Idin has laid out the code and template for how to enter passive mode, but do not like the implementation.  He\r\n      suggests that we overwrite a few of the builtin files for <a href=\"\"><tt>ftp<\/tt><\/a> and add new methods to it.  Overwriting shipping code is generally a bad idea and should be avoided unless Tech Support tells\r\n      you to.  It also means that with every MATLAB release, you have to repeat these steps with the new MATLAB version.  Instead,\r\n      Adam took his ideas, made a copy of <tt>ftp<\/tt> and renamed it <tt>customFTP<\/tt>. With customFTP on the path, it will work in any release and we won't be modifying any MATLAB shipping files or doing anything\r\n      else that could require UAC.\r\n   <\/p>\r\n   <p>For my <tt>ftplink<\/tt> function, I literally had to change a few characters and now it works everywhere:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainPassiveFTP\/ftplink.png\"> <\/p>\r\n   <p>Thanks Idin and Adam!<\/p>\r\n   <h3>Comments<a name=\"2\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=6168#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/6626-passive-mode-ftp-in-matlab#comments\">comment<\/a> for Idin.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_abeb7a7ef03b4dc1817f6a137e22bae8() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='abeb7a7ef03b4dc1817f6a137e22bae8 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' abeb7a7ef03b4dc1817f6a137e22bae8';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Sean de Wolski';\r\n        copyright = 'Copyright 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_abeb7a7ef03b4dc1817f6a137e22bae8()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015b<br><\/p>\r\n<\/div>\r\n<!--\r\nabeb7a7ef03b4dc1817f6a137e22bae8 ##### SOURCE BEGIN #####\r\n%% Passive FTP\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/6626-passive-mode-ftp-in-matlab Passive Mode FTP in MATLAB> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869996 Idin Motedayen>.\r\n% \r\n\r\n%% \r\n% My pick this week comes from former guest blogger, Idin Motedayen-Aval. I\r\n% spend a lot of my time interacting with MATLAB users and showing examples\r\n% of things you can do with the various MathWorks products.  After these\r\n% mettings, we always like to make the example available to everyone who\r\n% attended so they can learn from the material.  We use FTP for this since\r\n% the files tend to be large.\r\n% \r\n% I used to use FileZilla for this but since it's the same process, a\r\n% couple of years ago I automated it with MATLAB using a little utility\r\n% function called |ftplink|.  Here's the help for it:\r\n%\r\n%     % Usage:\r\n%     ftplink(name, file) - returns ftp link and uploads file to it\r\n%     ftplink(name)       - returns ftp link\r\n%     ftplink()           - returns home directory\r\n% \r\n% This function always worked great from MathWorks headquarters and from my\r\n% house but not from hotels or many other public wireless networks.  I just\r\n% assumed it was a firewall blocking it until I shared this utility with my\r\n% colleague, Adam, who pointed out that I was not using passive mode in FTP\r\n% - something new to me.  An explanation is\r\n% <http:\/\/slacksite.com\/other\/ftp.html here>.  He pointed me to Idin's\r\n% submission and said if I used it, it would work.\r\n%\r\n% I like that Idin has laid out the code and template for how to enter\r\n% passive mode, but do not like the implementation.  He suggests that we\r\n% overwrite a few of the builtin files for\r\n% <\r\n% |ftp|> and add new methods to it.  Overwriting shipping code is generally\r\n% a bad idea and should be avoided unless Tech Support tells you to.  It\r\n% also means that with every MATLAB release, you have to repeat these steps\r\n% with the new MATLAB version.  Instead, Adam took his ideas, made a copy\r\n% of |ftp| and renamed it |customFTP|. With customFTP on the path, it will\r\n% work in any release and we won't be modifying any MATLAB shipping files\r\n% or doing anything else that could require UAC.\r\n%\r\n% For my |ftplink| function, I literally had to change a few characters and\r\n% now it works everywhere:\r\n% \r\n% <<ftplink.png>>\r\n% \r\n% Thanks Idin and Adam!\r\n\r\n\r\n%% Comments\r\n% \r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=6168#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/6626-passive-mode-ftp-in-matlab#comments\r\n% comment> for Idin.\r\n%\r\n \r\n\r\n##### SOURCE END ##### abeb7a7ef03b4dc1817f6a137e22bae8\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainPassiveFTP\/ftplink.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is Passive Mode FTP in MATLAB by Idin Motedayen.\r\n      \r\n   \r\n\r\n   My pick this week comes from former guest blogger, Idin Motedayen-Aval. I spend a lot of... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2015\/09\/04\/passive-mode-ftp\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6168"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=6168"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6168\/revisions"}],"predecessor-version":[{"id":6172,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/6168\/revisions\/6172"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=6168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=6168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=6168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}