# Receiving files from an FTP Server

**URL:** <https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627>\
**Category:** Ignition\
**Created:** [January 17, 2018, 5:24pm UTC](https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627 "2018-01-17T17:24:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [January 17, 2018, 5:24pm UTC](https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627/1 "2018-01-17T17:24:13Z")

</div>

I’ve been asked for input on a method to receive XML files from an FTP server.  
My hope is that this is something that has been included in a module of some sort but I don’t really see a good answer her or when I ask Mr Google. In the same request it was noted that the files could be placed in a shared folder and then that folder monitored for new files to retrieve, though I don’t think this is the preferred method. Server Message Block (SMB) and Microsoft Message Que (MSMQ) were also mentioned.

Any input is appreciated,  
Mike

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 17, 2018, 5:35pm UTC](https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627/2 "2018-01-17T17:35:15Z")

</div>

The python standard FTPlib is included with our bundled Jython:  
[https://docs.python.org/2/library/ftplib.html](https://docs.python.org/2/library/ftplib.html)

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [January 18, 2018, 5:02am UTC](https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627/3 "2018-01-18T05:02:05Z")

</div>

Here is a quick example, using an FTP test site. I prefer to extend from Java classes, as I have had better luck with that, but this works for my test.

```auto
from ftplib import FTP #Import the ftp class
import StringIO #This gives us a string that looks like a file
s1 = StringIO.StringIO() #See above
s1.write("This is a test file\n") #Write our test string to our "file"
s1.seek(0) #Set the buffer index back to 0. If we don't, we can not read it
s2 = StringIO.StringIO() #Create our output string "file"
pftp = FTP("ftp.dlptest.com") #Connect to our ftp site
pftp.login("dlpuser@dlptest.com","hZ3Xr8alJPl8TtE") #Login
pftp.storlines('STOR Kyle-Test2.txt',s1) #Create or overwrite the location on the server. Write the context of s1 to that location
pftp.retrlines('LIST') #List the files on the server
pftp.retrlines('RETR Kyle-Test2.txt',s2.write) #Read the file from the server, writing the contents to our s2 string "file"
pftp.quit() #Close our ftp connection
print s2.getvalue() #Get the value of our string

```

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [January 22, 2018, 5:50pm UTC](https://forum.inductiveautomation.com/t/receiving-files-from-an-ftp-server/16627/4 "2018-01-22T17:50:04Z")

</div>

Thanks for the suggestions.  
Mike
