Python FTP

FTP servers are accessed through the fs library and any method the library supports is available to Zato services as well. Hence, the code below serves as a set of examples only, it is not a full reference.

Putting files on server

from zato.server.service import Service

class MyService(Service):

      def handle(self):
         conn = self.outgoing.ftp.get('My FTP')
         contents = conn.setcontents('/tmp/myfile', 'Hello\nFTP!\n')
$ cat /tmp/myfile
Hello
FTP!
$

Listing directories

from zato.server.service import Service

class MyService(Service):

      def handle(self):
         conn = self.outgoing.ftp.get('My FTP')
         listing = conn.listdir('/usr')
         self.logger.info(listing)
INFO - ['bin', 'src', 'sbin', 'lib32', 'lib', 'share', 'include']

Reading files

$ cat /tmp/myfile
123
456
789
$
from zato.server.service import Service

class MyService(Service):

      def handle(self):
         conn = self.outgoing.ftp.get('My FTP')
         contents = conn.getcontents('/tmp/myfile')
         self.logger.info(contents)


Schedule a meaningful demo

Book a demo with an expert who will help you build meaningful systems that match your ambitions

"For me, Zato Source is the only technology partner to help with operational improvements."

— John Adams
Program Manager of Channel Enablement at Keysight