File Exchange

image thumbnail

Passive Mode FTP in MATLAB

version (10.5 KB) by Idin Motedayen
These files allow users to use passive mode FTP in MATLAB.


Updated 29 Dec 2010

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

FTP clients working behind a firewall often use a passive mode FTP connection to the server to avoid issues with their firewall. MATLAB's ftp object does not have passive mode capability. The attached files modify this MATLAB class to allow for this functionality. These files simply use the Java methods available in the FTPClient Java class used by MATLAB.

See installation instructions in the README file.

Files/functionss added:

Files modified:

Update: December 29, 2010
- Updated install instructions allow this FTP class to work seamlessly with the MATLAB Compiler (original files will also work with Compiler if the new install instructions are followed).
- Improved the object to preserve connection mode (active/passive) if connection to host is lost and then reconnected.
- Updated files to use the R2010a version of FTP class.
- Tested with MATLAB R2010a and R2010b.

Original submission created in/for MATLAB R14SP1 is included as

Cite As

Idin Motedayen (2021). Passive Mode FTP in MATLAB (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (35)

Frederic Lange

Hello, I think the files locations have changed for r2020b. Would you be able to update the installation instructions as I don't want to mess up with my installation. Thanks!


Very helpful. Thank you. The detailed installation instructions were great. Functions worked on the first try!

Marine Fourrier

Martin Taillefer

Yep. That's a lifesaver.

Katarzyna Ste


This is fantastic! If I had not come across this fix, I don't know that I would have ever identified the source of the problem (let alone figured out a solution). Thank you for posting this! The explanation was helpful, and the installation instructions were straight forward and well described. Thanks!

Malcolm Wildgoose

Zihao Liu

I really appreciate this... Had a GoDaddy server, worked at FileZilla, but everything in dir() gone visible using Matlab ftp. Googled a while and found this one, really worked!!!! Thank you!

yinghao qin

very good tool to sovel my problem, great job for the developer

David Mayers

I was getting FTP error code 425 and this solved my issue. Very easy instructions to follow and it worked right away.



Works perfectly, solved my problem and detailed instructions on how to use it.

silvia landa

Sergei P.

Jorge Sierra

We have a problem to upload files to our FTP with Matlab and this add in. Before to install this addin we got FTP ERROR 500. Now, we installed this ftp addin and we put Matlab in passive mode, but we still getting errors.

test = ftp('','enersinc_ftp1','****************')
test =
FTP Object
user: enersinc_ftp1
dir: /home/enersinc_ftp1
mode: binary

mput(test, 'logo_Baja.png');


Courtney Miller

Thank you so much for sharing! This solved my problems. Great instructions as well


great, and a question more, how to kill the conneciotn when it encounters a bad ftp address after some time.


great help. it have solved my problem when connet FTP server using active method.


This code worked great for me in the past and seems to be failing now similar to using the active ftp. This is the error I am getting:
Error using
Java exception occurred: Connection
timed out

Error in ftp/mget (line 71)

Any thoughts on why it is failing now? Thanks for your time and I appreciate this code a lot!


Excellent! Ftp connection works again!



Solved my problem after spending a weekend restarting Matlab every time it got stuck during ftp downloads. Thanks.


This is a really great contribution. I struggled with some ftp code that previously was working fine, but broke when the lab IT infrastructure was updated - presumably because of a firewall. A quick google search brought me here, and within five minutes I had these files downloaded, installed, and my old code working again. Thank you!

Ryan Edwards

Just implemented on 2011a and everything appears to be working without problem. Thank you!

Idin Motedayen

Hi folks,
Thanks for downloading and rating this submission. For those trying to use this class with MATLAB Compiler, here's the fix:
1. Locate your @ftp folder and copy it to a location outside MATLAB toolbox directory.
2. Add the folder containing @ftp to the top of your MATLAB path.
3. Copy the provided connect.m into your new @ftp/private folder.
4. Copy the rest of the files to your new @ftp folder (ftp.m pasv.m, active.m, dataMode.m)
5. Restart MATLAB and rehash your toolbox cache by typing:
rehash toolboxcache
6. You can now use passive mode FTP as before, and if you compile the application, it will work.

I have updated the submission and install instructions. The update should hit the File Exchange in a few days.

Bryant Svedin

Thank you so much. This totally solved my problem. Luckily it took me just over an hour of frustration and google searching to find this instead of 3, 5 or more.

Darren Aklestad

Has anyone found a solution to using the passive mode in a compiled application via the MCRInstaller?

Peter Lindberg

Great, but the code only seems to work when I run it on my computer with Matlab installed. When I compile the code and run it with MCRInstaller, I guess It uses the original ftp code. Any tips, I've tried to copy the ftp.m code and rename it. Then including the renamed file when I compile, but I cannot use the function class(h,'ftp'). My guess is that ftp.m must be located in .../@ftp/

Jaime Zamora

Ray Goldsworthy

Fantastic! Solved my ftp 500 errors when downloading directories. Thank you!

Moroni Noronha

This is the fix I was looking for after 5 hours looking everywhere. Works for Windows XP!! Thank you very much for this product.

Siyi Deng

works great; solved the java IO stream error problem form me

Ron Abileah

Well written instructions. This is one of the best contributions I have found in over two years of using the Mathworks Exchange. Many thanks.

I struggled for three hours trying to get the MATHWORKS ftp routines to work. Had no luck. I finally suspected that the firewall(s) were getting in the way of making ftp work. I then searched and found Idin Motedayen's passive ftp routines. I downloaded his zip and in 10 minutes I was doing ftp up & downloads within my MATLAB program.

Chris Nafis

This is great! Just what I needed to get consistent FTPs thru our firewall. Nice installation directions.

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: F10.7 Solar Flux & Ap Indices

Community Treasure Hunt

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

Start Hunting!