**- Undocumented Matlab - https://undocumentedmatlab.com -**

Solving an mput (FTP) hang problem

Posted By Yair Altman On August 19, 2015 | __3 Comments__

Matlab includes a variety of builtin utility functions that enable easy access to FTP. These functions are basically methods of an FTP object using Matlab’s old class system (for example, the * mput* function is implemented as

I recently needed to upload files from Matlab onto an FTP server, and discovered that calling

Some online research yielded others who have complained about similar issues over the years, but I saw no concrete answer. I saw many references online to problems that relate to the combination of passive FTP with Windows 7 / firewall / Java 7, that suggested several fixes (example 1

Today, Malcolm Lidierth, author of the Waterloo graphics package

This can be done in two manners:

The easiest is to add the following highlighted line in

```
...
% Upload this file.
fis = java.io.FileInputStream(fileObject);
h.jobject.enterLocalPassiveMode(); % Use passive mode
status = h.jobject.storeFile(name,fis);
fis.close;
...
```

This works but has several limitations:

- it does not solve the problems of other passive FTP commands such as
, although they can be solved in a similar manner**dir** - it creates a counter-problem when connecting to non-passive FTP servers – users might wish to make this a parameter of the
constructor function**ftp** - and of course it requires changing Matlab’s installation files which is problematic in many aspects, as well as non-portable if you ever use your program on another machine or Matlab release.

Here’s a much simpler, portable and flexible solution: simply set the underlying Java object’s passive mode after connecting to the server (using the * ftp* constructor function) but before using

```
f = ftp('myftpserver.com',username,password);
cd(f); sf=struct(f); sf.jobject.enterLocalPassiveMode();
mput(f,filename);
dir(f);
close(f);
```

Note that we need to connect first, then get the underlying Java reference using the * struct* hack

`f.jobject`

is prevented), then we enter local passive mode, and only then we call This way, we can programmatically control when to use passive mode, and no changes to the Matlab install files is required: our Matlab script should now work on all platforms and Matlab releases.

Note the seemingly unnecessary call to

As an interesting related note,

`FTPClientConfig`

`FTPClient`

I will be traveling to north Italy between Aug 26 – Sep 1, 2015. If you happen to be in the area at that time, I will be happy to meet you to discuss how I could bring value to your work. Please email me (altmany at gmail) if you are interested.

Due to my travel, this blog will take a short summer vacation, and will return in early September. Stay tuned!

Categories: Java, Medium risk of breaking in future versions, Stock Matlab function, Undocumented feature

3 Comments (Open | Close)

Article printed from Undocumented Matlab: **https://undocumentedmatlab.com**

URL to article: **https://undocumentedmatlab.com/articles/solving-an-mput-ftp-hang-problem**

URLs in this post:

[1] example 1: **https://technet.microsoft.com/en-us/library/dd421710(v=ws.10).aspx**

[2] example 2: **https://support.microsoft.com/en-us/kb/2754804**

[3] example 3: **http://stackoverflow.com/questions/6990663/java-7-prevents-ftp-transfers-on-windows-vista-and-7-if-firewall-is-on-any-idea**

[4] example 4: **http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7077696**

[5] Waterloo graphics package: **http://undocumentedmatlab.com/blog/tag/waterloo**

[6] * struct* hack:

[7] `FTPClientConfig`

: **http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClientConfig.html**

[8] `FTPClient`

: **http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html**

[9] *enterLocalPassiveMode*: **http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#enterLocalPassiveMode()**

[10] Solving a Matlab hang problem : **https://undocumentedmatlab.com/articles/solving-a-matlab-hang-problem**

[11] Solving a Matlab MCOS bug : **https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug**

[12] Solving a MATLAB bug by subclassing : **https://undocumentedmatlab.com/articles/solving-a-matlab-bug-by-subclassing**

[13] Java class access pitfalls : **https://undocumentedmatlab.com/articles/java-class-access-pitfalls**

[14] Using pure Java GUI in deployed Matlab apps : **https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps**

[15] More undocumented timing features : **https://undocumentedmatlab.com/articles/more-undocumented-timing-features**

Click here to print.

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.

3 Comments To "Solving an mput (FTP) hang problem"

#1 CommentBySamuel BrocksoppOn November 29, 2016 @ 13:37Hi there,

I have been suffering the burden of MATLAB’s FTP functions for a few days now. Like you stated in your post, some of the other solutions are not ideal or portable. Thank you very much for posting this! Your website is a great resource, keep up the good work.

Brocksopp

#2 CommentByEnesOn February 6, 2018 @ 07:53I was facing the same problem. When I used dir(f) command the code would just get stuck. Using the line: “sf=struct(f); sf.jobject.enterLocalPassiveMode();” to switch to passive mode as you have pointed out solved my problem. Thank you.

#3 CommentByMoghOn April 5, 2018 @ 09:44My same problem with “mput” function is solved.

thanks a lot for your useful suggestion.